Adhere to const'ness of the input data in encrypt_block_impl.

This commit is contained in:
Michael Jung 2005-01-03 20:14:03 +00:00 committed by Alexandre Julliard
parent 6971e1d762
commit 0da8a5219e

View file

@ -259,6 +259,8 @@ BOOL encrypt_block_impl(ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext, CONST BYTE *in
DWORD enc) DWORD enc)
{ {
unsigned long inlen, outlen; unsigned long inlen, outlen;
BYTE *in_reversed = NULL;
int key;
switch (aiAlgid) { switch (aiAlgid) {
case CALG_RC2: case CALG_RC2:
@ -287,36 +289,38 @@ BOOL encrypt_block_impl(ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext, CONST BYTE *in
break; break;
case CALG_RSA_KEYX: case CALG_RSA_KEYX:
outlen = inlen = (mp_count_bits(&pKeyContext->rsa.N)+7)/8;
if (enc) {
if (rsa_exptmod(in, inlen, out, &outlen, PK_PUBLIC, &pKeyContext->rsa) != CRYPT_OK) {
SetLastError(NTE_FAIL);
return FALSE;
}
reverse_bytes((BYTE*)out, outlen);
} else {
reverse_bytes((BYTE*)in, inlen);
if (rsa_exptmod(in, inlen, out, &outlen, PK_PRIVATE, &pKeyContext->rsa) != CRYPT_OK) {
SetLastError(NTE_FAIL);
return FALSE;
}
}
break;
case CALG_RSA_SIGN: case CALG_RSA_SIGN:
outlen = inlen = (mp_count_bits(&pKeyContext->rsa.N)+7)/8; outlen = inlen = (mp_count_bits(&pKeyContext->rsa.N)+7)/8;
if (enc) { if (enc) {
if (rsa_exptmod(in, inlen, out, &outlen, PK_PRIVATE, &pKeyContext->rsa) != CRYPT_OK) { if (aiAlgid == CALG_RSA_SIGN) {
key = PK_PRIVATE;
} else {
key = PK_PUBLIC;
}
if (rsa_exptmod(in, inlen, out, &outlen, key, &pKeyContext->rsa) != CRYPT_OK) {
SetLastError(NTE_FAIL); SetLastError(NTE_FAIL);
return FALSE; return FALSE;
} }
reverse_bytes((BYTE*)out, outlen); reverse_bytes(out, outlen);
} else { } else {
reverse_bytes((BYTE*)in, inlen); if (aiAlgid == CALG_RSA_SIGN) {
if (rsa_exptmod(in, inlen, out, &outlen, PK_PUBLIC, &pKeyContext->rsa) != CRYPT_OK) { key = PK_PUBLIC;
} else {
key = PK_PRIVATE;
}
in_reversed = HeapAlloc(GetProcessHeap(), 0, inlen);
if (!in_reversed) {
SetLastError(NTE_NO_MEMORY);
return FALSE;
}
memcpy(in_reversed, in, inlen);
reverse_bytes(in_reversed, inlen);
if (rsa_exptmod(in_reversed, inlen, out, &outlen, key, &pKeyContext->rsa) != CRYPT_OK) {
HeapFree(GetProcessHeap(), 0, in_reversed);
SetLastError(NTE_FAIL); SetLastError(NTE_FAIL);
return FALSE; return FALSE;
} }
HeapFree(GetProcessHeap(), 0, in_reversed);
} }
break; break;