bigpdiv.c revision 65c4736d9c0ebc6d9b1d991593b55566909da9cd
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt/* Copyright (C) RSA Data Security, Inc. created 1986, 1996. This is an
699f790c49d03a9ef3c3234a72d272bb469203e8Evan Hunt unpublished work protected as such under copyright law. This work
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt contains proprietary, confidential, and trade secret information of
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews RSA Data Security, Inc. Use, disclosure or reproduction without the
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews express written authorization of RSA Data Security, Inc. is
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt/* BigPdiv POSITIVE DIVIDE
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt uu=vv * qi+ri
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt uu in reg of ll cells
699f790c49d03a9ef3c3234a72d272bb469203e8Evan Hunt vv in reg of kk cells
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt qi assumed to be ll cells
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt ri assumed to be kk cells
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt restriction uu>=0, vv>0
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt input uu in reg of ll cells
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt input vv in reg of kk cells
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt output qi assumed to be ll cells
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt output ri assumed to be kk cells
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt restriction uu>=0, vv>0
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt uu=vv * qi+ri
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt UINT2 u[2 * MAX_RSA_PRIME_WORDS + 2], us[2 * MAX_RSA_PRIME_WORDS + 2],
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt v[2 * MAX_RSA_PRIME_WORDS + 2], vs[2 * MAX_RSA_PRIME_WORDS + 2],
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt q[2 * MAX_RSA_PRIME_WORDS + 2], r[2 * MAX_RSA_PRIME_WORDS + 2],
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt t1[2 * MAX_RSA_PRIME_WORDS + 2], t2[2 * MAX_RSA_PRIME_WORDS + 2],
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt int j, l, n, m, t, x;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* zero q */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* Calculate len of v=n.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* Normalize.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt d = b / (a+1);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* vh=high order digit of normalized v */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* Calculate len of u=t.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* calc t = n + m */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* Divide u by v.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt for (j = m + 1 + n; j > n; j--) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt c = u[j / 2];
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* Adjust q.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt for (x = 0; ; qq --, x ++) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* Check result.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* t2 has remainder */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* transfer results to input registers */