Commit 1dbaa8c6 authored by Vijay Kiran Kamuju's avatar Vijay Kiran Kamuju Committed by Alexandre Julliard

rsaenh: Add implementation of Enhanced RSA AES Provider.

parent ea1f8c7a
......@@ -8,6 +8,7 @@ IMPORTLIB = librsaenh.$(IMPLIBEXT)
IMPORTS = crypt32 advapi32 kernel32
C_SRCS = \
aes.c \
des.c \
handle.c \
implglue.c \
......
......@@ -3,6 +3,7 @@
* Glueing the RSAENH specific code to the crypto library
*
* Copyright (c) 2004, 2005 Michael Jung
* Copyright (c) 2007 Vijay Kiran Kamuju
*
* based on code by Mike McCormack and David Hammerton
*
......@@ -194,6 +195,19 @@ BOOL setup_key_impl(ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext, DWORD dwKeyLen,
case CALG_DES:
des_setup(abKeyValue, 8, 0, &pKeyContext->des);
break;
case CALG_AES:
case CALG_AES_128:
aes_setup(abKeyValue, 16, 0, &pKeyContext->aes);
break;
case CALG_AES_192:
aes_setup(abKeyValue, 24, 0, &pKeyContext->aes);
break;
case CALG_AES_256:
aes_setup(abKeyValue, 32, 0, &pKeyContext->aes);
break;
}
return TRUE;
......@@ -209,6 +223,10 @@ BOOL duplicate_key_impl(ALG_ID aiAlgid, CONST KEY_CONTEXT *pSrcKeyContext,
case CALG_3DES:
case CALG_3DES_112:
case CALG_DES:
case CALG_AES:
case CALG_AES_128:
case CALG_AES_192:
case CALG_AES_256:
memcpy(pDestKeyContext, pSrcKeyContext, sizeof(KEY_CONTEXT));
break;
case CALG_RSA_KEYX:
......@@ -275,6 +293,17 @@ BOOL encrypt_block_impl(ALG_ID aiAlgid, DWORD dwKeySpec, KEY_CONTEXT *pKeyContex
}
break;
case CALG_AES:
case CALG_AES_128:
case CALG_AES_192:
case CALG_AES_256:
if (enc) {
aes_ecb_encrypt(in, out, &pKeyContext->aes);
} else {
aes_ecb_decrypt(in, out, &pKeyContext->aes);
}
break;
case CALG_RSA_KEYX:
case CALG_RSA_SIGN:
outlen = inlen = (mp_count_bits(&pKeyContext->rsa.N)+7)/8;
......
......@@ -63,6 +63,7 @@ typedef union tagKEY_CONTEXT {
rc2_key rc2;
des_key des;
des3_key des3;
aes_key aes;
prng_state rc4;
rsa_key rsa;
} KEY_CONTEXT;
......
......@@ -140,31 +140,21 @@ static int init_aes_environment(void)
* This provider is available on Windows XP, Windows 2003 and Vista. */
result = CryptAcquireContext(&hProv, szContainer, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT);
todo_wine {
ok(!result && GetLastError()==NTE_BAD_FLAGS, "%d, %08x\n", result, GetLastError());
}
if (!CryptAcquireContext(&hProv, szContainer, NULL, PROV_RSA_AES, 0))
{
todo_wine {
ok(GetLastError()==NTE_BAD_KEYSET, "%08x\n", GetLastError());
}
if (GetLastError()!=NTE_BAD_KEYSET) return 0;
result = CryptAcquireContext(&hProv, szContainer, NULL, PROV_RSA_AES,
CRYPT_NEWKEYSET);
todo_wine {
ok(result, "%08x\n", GetLastError());
}
if (!result) return 0;
result = CryptGenKey(hProv, AT_KEYEXCHANGE, 0, &hKey);
todo_wine {
ok(result, "%08x\n", GetLastError());
}
if (result) CryptDestroyKey(hKey);
result = CryptGenKey(hProv, AT_SIGNATURE, 0, &hKey);
todo_wine {
ok(result, "%08x\n", GetLastError());
}
if (result) CryptDestroyKey(hKey);
}
return 1;
......@@ -175,7 +165,7 @@ static void clean_up_aes_environment(void)
BOOL result;
result = CryptReleaseContext(hProv, 1);
todo_wine ok(!result && GetLastError()==NTE_BAD_FLAGS, "%08x\n", GetLastError());
ok(!result && GetLastError()==NTE_BAD_FLAGS, "%08x\n", GetLastError());
CryptAcquireContext(&hProv, szContainer, NULL, PROV_RSA_AES, CRYPT_DELETEKEYSET);
}
......@@ -670,14 +660,10 @@ static void test_aes(int keylen)
dwLen = 13;
result = CryptEncrypt(hKey, (HCRYPTHASH)NULL, TRUE, 0, pbData, &dwLen, 16);
todo_wine {
ok(result, "%08x\n", GetLastError());
}
result = CryptDecrypt(hKey, (HCRYPTHASH)NULL, TRUE, 0, pbData, &dwLen);
todo_wine {
ok(result, "%08x\n", GetLastError());
}
for (i=0; i<4; i++)
{
......@@ -685,13 +671,10 @@ static void test_aes(int keylen)
dwLen = cTestData[i].enclen;
result = CryptEncrypt(hKey, (HCRYPTHASH)NULL, TRUE, 0, pbData, &dwLen, cTestData[i].buflen);
todo_wine {
ok(result, "%08x\n", GetLastError());
ok(dwLen==cTestData[i].buflen,"length incorrect, got %d, expected %d\n",dwLen,cTestData[i].buflen);
}
result = CryptDecrypt(hKey, (HCRYPTHASH)NULL, TRUE, 0, pbData, &dwLen);
todo_wine {
ok(result, "%08x\n", GetLastError());
ok(dwLen==cTestData[i].enclen,"length incorrect, got %d, expected %d\n",dwLen,cTestData[i].enclen);
ok(memcmp(pbData,cTestData[i].decstr,cTestData[1].enclen)==0,"decryption incorrect %d\n",i);
......@@ -701,12 +684,9 @@ static void test_aes(int keylen)
printBytes("expected",cTestData[i].decstr,cTestData[i].strlen);
printBytes("got",pbData,dwLen);
}
}
}
result = CryptDestroyKey(hKey);
todo_wine {
ok(result, "%08x\n", GetLastError());
}
}
static void test_rc2(void)
......
......@@ -129,6 +129,11 @@ typedef struct tag_des3_key {
ulong32 ek[3][32], dk[3][32];
} des3_key;
typedef struct tag_aes_key {
ulong32 eK[64], dK[64];
int Nr;
} aes_key;
int rc2_setup(const unsigned char *key, int keylen, int bits, int num_rounds, rc2_key *skey);
void rc2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, rc2_key *key);
void rc2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, rc2_key *key);
......@@ -141,6 +146,10 @@ int des3_setup(const unsigned char *key, int keylen, int num_rounds, des3_key *s
void des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const des3_key *key);
void des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const des3_key *key);
int aes_setup(const unsigned char *key, int keylen, int rounds, aes_key *skey);
void aes_ecb_encrypt(const unsigned char *pt, unsigned char *ct, aes_key *skey);
void aes_ecb_decrypt(const unsigned char *ct, unsigned char *pt, aes_key *skey);
typedef struct tag_md2_state {
unsigned char chksum[16], X[48], buf[16];
unsigned long curlen;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment