sync rsaenh to wine 1.1.11

svn path=/trunk/; revision=38373
This commit is contained in:
Christoph von Wittich 2008-12-27 10:11:34 +00:00
parent a4c232b9e4
commit 128f584a7d
5 changed files with 36 additions and 44 deletions

View file

@ -77,7 +77,7 @@ static void md2_compress(md2_state *md2)
md2->X[32+j] = md2->X[j] ^ md2->X[16+j];
}
t = (unsigned char)0;
t = 0;
/* do 18 rounds */
for (j = 0; j < 18; j++) {

View file

@ -39,13 +39,26 @@
static const int KARATSUBA_MUL_CUTOFF = 88, /* Min. number of digits before Karatsuba multiplication is used. */
KARATSUBA_SQR_CUTOFF = 128; /* Min. number of digits before Karatsuba squaring is used. */
static void bn_reverse(unsigned char *s, int len);
static int s_mp_add(mp_int *a, mp_int *b, mp_int *c);
static int s_mp_exptmod (const mp_int * G, const mp_int * X, mp_int * P, mp_int * Y);
#define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1)
static int s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs);
static int s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs);
static int s_mp_sqr(const mp_int *a, mp_int *b);
static int s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c);
static int mp_exptmod_fast(const mp_int *G, const mp_int *X, mp_int *P, mp_int *Y, int mode);
static int mp_invmod_slow (const mp_int * a, mp_int * b, mp_int * c);
static int mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c);
static int mp_karatsuba_sqr(const mp_int *a, mp_int *b);
/* computes the modular inverse via binary extended euclidean algorithm,
* that is c = 1/a mod b
*
* Based on slow invmod except this is optimized for the case where b is
* odd as per HAC Note 14.64 on pp. 610
*/
int
static int
fast_mp_invmod (const mp_int * a, mp_int * b, mp_int * c)
{
mp_int x, y, u, v, B, D;
@ -175,7 +188,7 @@ __ERR:mp_clear_multi (&x, &y, &u, &v, &B, &D, NULL);
*
* Based on Algorithm 14.32 on pp.601 of HAC.
*/
int
static int
fast_mp_montgomery_reduce (mp_int * x, const mp_int * n, mp_digit rho)
{
int ix, res, olduse;
@ -335,7 +348,7 @@ fast_mp_montgomery_reduce (mp_int * x, const mp_int * n, mp_digit rho)
* Based on Algorithm 14.12 on pp.595 of HAC.
*
*/
int
static int
fast_s_mp_mul_digs (const mp_int * a, const mp_int * b, mp_int * c, int digs)
{
int olduse, res, pa, ix, iz;
@ -414,7 +427,7 @@ fast_s_mp_mul_digs (const mp_int * a, const mp_int * b, mp_int * c, int digs)
*
* Based on Algorithm 14.12 on pp.595 of HAC.
*/
int
static int
fast_s_mp_mul_high_digs (const mp_int * a, const mp_int * b, mp_int * c, int digs)
{
int olduse, res, pa, ix, iz;
@ -512,7 +525,7 @@ Remove W2 and don't memset W
*/
int fast_s_mp_sqr (const mp_int * a, mp_int * b)
static int fast_s_mp_sqr (const mp_int * a, mp_int * b)
{
int olduse, res, pa, ix, iz;
mp_digit W[MP_WARRAY], *tmpx;
@ -996,7 +1009,7 @@ mp_count_bits (const mp_int * a)
/* take the last digit and count the bits in it */
q = a->dp[a->used - 1];
while (q > ((mp_digit) 0)) {
while (q > 0) {
++r;
q >>= ((mp_digit) 1);
}
@ -3847,7 +3860,7 @@ mp_zero (mp_int * a)
}
/* reverse an array, used for radix code */
void
static void
bn_reverse (unsigned char *s, int len)
{
int ix, iy;
@ -3865,7 +3878,7 @@ bn_reverse (unsigned char *s, int len)
}
/* low level addition, based on HAC pp.594, Algorithm 14.7 */
int
static int
s_mp_add (mp_int * a, mp_int * b, mp_int * c)
{
mp_int *x;
@ -3952,7 +3965,7 @@ s_mp_add (mp_int * a, mp_int * b, mp_int * c)
return MP_OKAY;
}
int s_mp_exptmod (const mp_int * G, const mp_int * X, mp_int * P, mp_int * Y)
static int s_mp_exptmod (const mp_int * G, const mp_int * X, mp_int * P, mp_int * Y)
{
mp_int M[256], res, mu;
mp_digit buf;
@ -4163,7 +4176,7 @@ __M:
* HAC pp. 595, Algorithm 14.12 Modified so you can control how
* many digits of output are created.
*/
int
static int
s_mp_mul_digs (const mp_int * a, const mp_int * b, mp_int * c, int digs)
{
mp_int t;
@ -4232,7 +4245,7 @@ s_mp_mul_digs (const mp_int * a, const mp_int * b, mp_int * c, int digs)
/* multiplies |a| * |b| and does not compute the lower digs digits
* [meant to get the higher part of the product]
*/
int
static int
s_mp_mul_high_digs (const mp_int * a, const mp_int * b, mp_int * c, int digs)
{
mp_int t;
@ -4288,7 +4301,7 @@ s_mp_mul_high_digs (const mp_int * a, const mp_int * b, mp_int * c, int digs)
}
/* low level squaring, b = a*a, HAC pp.596-597, Algorithm 14.16 */
int
static int
s_mp_sqr (const mp_int * a, mp_int * b)
{
mp_int t;
@ -4338,7 +4351,7 @@ s_mp_sqr (const mp_int * a, mp_int * b)
u = (mp_digit)(r >> ((mp_word) DIGIT_BIT));
}
/* propagate upwards */
while (u != ((mp_digit) 0)) {
while (u != 0) {
r = ((mp_word) *tmpt) + ((mp_word) u);
*tmpt++ = (mp_digit) (r & ((mp_word) MP_MASK));
u = (mp_digit)(r >> ((mp_word) DIGIT_BIT));

View file

@ -70,7 +70,7 @@ int rc2_setup(const unsigned char *key, int keylen, int bits, int rounds, rc2_ke
* key schedule. One which is normal, and anther which has a hook to
* use a reduced key length.
* BSAFE uses the 'retarded' version. What I previously shipped is
* the same as specifying 1024 for the 'bits' parameter. Bsafe uses
* the same as specifying 1024 for the 'bits' parameter. BSAFE uses
* a version where the bits parameter is the same as len*8 */
/* Seems like MS uses the 'retarded' version, too.
* Adjust effective keylen bits */

View file

@ -657,7 +657,7 @@ static inline void update_hash(CRYPTHASH *pCryptHash, CONST BYTE *pbData, DWORD
pbTemp = HeapAlloc(GetProcessHeap(), 0, dwDataLen);
if (!pbTemp) return;
memcpy(pbTemp, pbData, dwDataLen);
RSAENH_CPEncrypt(pCryptHash->hProv, pCryptHash->hKey, (HCRYPTHASH)NULL, FALSE, 0,
RSAENH_CPEncrypt(pCryptHash->hProv, pCryptHash->hKey, 0, FALSE, 0,
pbTemp, &dwDataLen, dwDataLen);
HeapFree(GetProcessHeap(), 0, pbTemp);
break;
@ -701,7 +701,7 @@ static inline void finalize_hash(CRYPTHASH *pCryptHash) {
case CALG_MAC:
dwDataLen = 0;
RSAENH_CPEncrypt(pCryptHash->hProv, pCryptHash->hKey, (HCRYPTHASH)NULL, TRUE, 0,
RSAENH_CPEncrypt(pCryptHash->hProv, pCryptHash->hKey, 0, TRUE, 0,
pCryptHash->abHashValue, &dwDataLen, pCryptHash->dwHashSize);
break;
@ -1259,7 +1259,7 @@ static BOOL build_hash_signature(BYTE *pbSignature, DWORD dwLen, ALG_ID aiAlgid,
0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10 } },
{ CALG_SHA, 15, { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03,
0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 } },
{ 0, 0, {} }
{ 0, 0, { 0 } }
};
DWORD dwIdxOID, i, j;
@ -1677,7 +1677,7 @@ BOOL WINAPI RSAENH_CPCreateHash(HCRYPTPROV hProv, ALG_ID Algid, HCRYPTKEY hKey,
pCryptHash->hKey = hKey;
pCryptHash->hProv = hProv;
pCryptHash->dwState = RSAENH_HASHSTATE_HASHING;
pCryptHash->pHMACInfo = (PHMAC_INFO)NULL;
pCryptHash->pHMACInfo = NULL;
pCryptHash->dwHashSize = peaAlgidInfo->dwDefaultLen >> 3;
init_data_blob(&pCryptHash->tpPRFParams.blobLabel);
init_data_blob(&pCryptHash->tpPRFParams.blobSeed);
@ -2826,10 +2826,10 @@ BOOL WINAPI RSAENH_CPSetKeyParam(HCRYPTPROV hProv, HCRYPTKEY hKey, DWORD dwParam
{
CRYPT_INTEGER_BLOB *blob = (CRYPT_INTEGER_BLOB *)pbData;
/* salt length can't be greater than 128 bits = 16 bytes */
if (blob->cbData > 16)
/* salt length can't be greater than 184 bits = 24 bytes */
if (blob->cbData > 24)
{
SetLastError(ERROR_INVALID_PARAMETER);
SetLastError(NTE_BAD_DATA);
return FALSE;
}
memcpy(pCryptKey->abKeyValue + pCryptKey->dwKeyLen, blob->pbData,
@ -3557,7 +3557,7 @@ BOOL WINAPI RSAENH_CPSetHashParam(HCRYPTPROV hProv, HCRYPTHASH hHash, DWORD dwPa
{
CRYPTHASH *pCryptHash;
CRYPTKEY *pCryptKey;
int i;
DWORD i;
TRACE("(hProv=%08lx, hHash=%08lx, dwParam=%08x, pbData=%p, dwFlags=%08x)\n",
hProv, hHash, dwParam, pbData, dwFlags);

View file

@ -574,27 +574,6 @@ int mp_fwrite(mp_int *a, int radix, FILE *stream);
#define mp_todecimal(M, S) mp_toradix((M), (S), 10)
#define mp_tohex(M, S) mp_toradix((M), (S), 16)
/* lowlevel functions, do not call! */
int s_mp_add(mp_int *a, mp_int *b, mp_int *c);
int s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c);
#define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1)
int fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs);
int s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs);
int fast_s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs);
int s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs);
int fast_s_mp_sqr(const mp_int *a, mp_int *b);
int s_mp_sqr(const mp_int *a, mp_int *b);
int mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c);
int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c);
int mp_karatsuba_sqr(const mp_int *a, mp_int *b);
int mp_toom_sqr(mp_int *a, mp_int *b);
int fast_mp_invmod(const mp_int *a, mp_int *b, mp_int *c);
int mp_invmod_slow (const mp_int * a, mp_int * b, mp_int * c);
int fast_mp_montgomery_reduce(mp_int *a, const mp_int *m, mp_digit mp);
int mp_exptmod_fast(const mp_int *G, const mp_int *X, mp_int *P, mp_int *Y, int mode);
int s_mp_exptmod (const mp_int * G, const mp_int * X, mp_int * P, mp_int * Y);
void bn_reverse(unsigned char *s, int len);
extern const char *mp_s_rmap;
#define PK_PRIVATE 0 /* PK private keys */