mirror of
https://github.com/reactos/reactos.git
synced 2025-05-25 12:14:32 +00:00
-sync rsaenh with wine 1.1.32
svn path=/trunk/; revision=43755
This commit is contained in:
parent
14c61c9004
commit
a0951dacc4
2 changed files with 106 additions and 12 deletions
|
@ -777,6 +777,8 @@ static HCRYPTKEY new_key(HCRYPTPROV hProv, ALG_ID aiAlgid, DWORD dwFlags, CRYPTK
|
||||||
peaAlgidInfo = get_algid_info(hProv, aiAlgid);
|
peaAlgidInfo = get_algid_info(hProv, aiAlgid);
|
||||||
if (!peaAlgidInfo) return (HCRYPTKEY)INVALID_HANDLE_VALUE;
|
if (!peaAlgidInfo) return (HCRYPTKEY)INVALID_HANDLE_VALUE;
|
||||||
|
|
||||||
|
TRACE("alg = %s, dwKeyLen = %d\n", debugstr_a(peaAlgidInfo->szName),
|
||||||
|
dwKeyLen);
|
||||||
/*
|
/*
|
||||||
* Assume the default key length, if none is specified explicitly
|
* Assume the default key length, if none is specified explicitly
|
||||||
*/
|
*/
|
||||||
|
@ -822,7 +824,9 @@ static HCRYPTKEY new_key(HCRYPTPROV hProv, ALG_ID aiAlgid, DWORD dwFlags, CRYPTK
|
||||||
dwKeyLen > peaAlgidInfo->dwMaxLen ||
|
dwKeyLen > peaAlgidInfo->dwMaxLen ||
|
||||||
dwKeyLen < peaAlgidInfo->dwMinLen)
|
dwKeyLen < peaAlgidInfo->dwMinLen)
|
||||||
{
|
{
|
||||||
SetLastError(NTE_BAD_FLAGS);
|
TRACE("key len %d out of bounds (%d, %d)\n", dwKeyLen,
|
||||||
|
peaAlgidInfo->dwMinLen, peaAlgidInfo->dwMaxLen);
|
||||||
|
SetLastError(NTE_BAD_DATA);
|
||||||
return (HCRYPTKEY)INVALID_HANDLE_VALUE;
|
return (HCRYPTKEY)INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2481,6 +2485,33 @@ static BOOL crypt_export_private_key(CRYPTKEY *pCryptKey, BOOL force,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static BOOL crypt_export_plaintext_key(CRYPTKEY *pCryptKey, BYTE *pbData,
|
||||||
|
DWORD *pdwDataLen)
|
||||||
|
{
|
||||||
|
BLOBHEADER *pBlobHeader = (BLOBHEADER*)pbData;
|
||||||
|
DWORD *pKeyLen = (DWORD*)(pBlobHeader+1);
|
||||||
|
BYTE *pbKey = (BYTE*)(pKeyLen+1);
|
||||||
|
DWORD dwDataLen;
|
||||||
|
|
||||||
|
dwDataLen = sizeof(BLOBHEADER) + sizeof(DWORD) + pCryptKey->dwKeyLen;
|
||||||
|
if (pbData) {
|
||||||
|
if (*pdwDataLen < dwDataLen) {
|
||||||
|
SetLastError(ERROR_MORE_DATA);
|
||||||
|
*pdwDataLen = dwDataLen;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
pBlobHeader->bType = PLAINTEXTKEYBLOB;
|
||||||
|
pBlobHeader->bVersion = CUR_BLOB_VERSION;
|
||||||
|
pBlobHeader->reserved = 0;
|
||||||
|
pBlobHeader->aiKeyAlg = pCryptKey->aiAlgid;
|
||||||
|
|
||||||
|
*pKeyLen = pCryptKey->dwKeyLen;
|
||||||
|
memcpy(pbKey, &pCryptKey->abKeyValue, pCryptKey->dwKeyLen);
|
||||||
|
}
|
||||||
|
*pdwDataLen = dwDataLen;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* crypt_export_key [Internal]
|
* crypt_export_key [Internal]
|
||||||
*
|
*
|
||||||
|
@ -2536,6 +2567,9 @@ static BOOL crypt_export_key(CRYPTKEY *pCryptKey, HCRYPTKEY hPubKey,
|
||||||
case PRIVATEKEYBLOB:
|
case PRIVATEKEYBLOB:
|
||||||
return crypt_export_private_key(pCryptKey, force, pbData, pdwDataLen);
|
return crypt_export_private_key(pCryptKey, force, pbData, pdwDataLen);
|
||||||
|
|
||||||
|
case PLAINTEXTKEYBLOB:
|
||||||
|
return crypt_export_plaintext_key(pCryptKey, pbData, pdwDataLen);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
SetLastError(NTE_BAD_TYPE); /* FIXME: error code? */
|
SetLastError(NTE_BAD_TYPE); /* FIXME: error code? */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -2833,6 +2867,53 @@ static BOOL import_symmetric_key(HCRYPTPROV hProv, CONST BYTE *pbData,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* import_plaintext_key [Internal]
|
||||||
|
*
|
||||||
|
* Import a plaintext key into a key container.
|
||||||
|
*
|
||||||
|
* PARAMS
|
||||||
|
* hProv [I] Key container into which the symmetric key is to be imported.
|
||||||
|
* pbData [I] Pointer to a buffer which holds the plaintext key BLOB.
|
||||||
|
* dwDataLen [I] Length of data in buffer at pbData.
|
||||||
|
* dwFlags [I] One of:
|
||||||
|
* CRYPT_EXPORTABLE: the imported key is marked exportable
|
||||||
|
* phKey [O] Handle to the imported key.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTES
|
||||||
|
* Assumes the caller has already checked the BLOBHEADER at pbData to ensure
|
||||||
|
* it's a PLAINTEXTKEYBLOB.
|
||||||
|
*
|
||||||
|
* RETURNS
|
||||||
|
* Success: TRUE.
|
||||||
|
* Failure: FALSE.
|
||||||
|
*/
|
||||||
|
static BOOL import_plaintext_key(HCRYPTPROV hProv, CONST BYTE *pbData,
|
||||||
|
DWORD dwDataLen, DWORD dwFlags,
|
||||||
|
HCRYPTKEY *phKey)
|
||||||
|
{
|
||||||
|
CRYPTKEY *pCryptKey;
|
||||||
|
CONST BLOBHEADER *pBlobHeader = (CONST BLOBHEADER*)pbData;
|
||||||
|
CONST DWORD *pKeyLen = (CONST DWORD *)(pBlobHeader + 1);
|
||||||
|
CONST BYTE *pbKeyStream = (CONST BYTE*)(pKeyLen + 1);
|
||||||
|
|
||||||
|
if (dwDataLen < sizeof(BLOBHEADER)+sizeof(DWORD)+*pKeyLen)
|
||||||
|
{
|
||||||
|
SetLastError(NTE_BAD_DATA); /* FIXME: error code */
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*phKey = new_key(hProv, pBlobHeader->aiKeyAlg, *pKeyLen<<19, &pCryptKey);
|
||||||
|
if (*phKey == (HCRYPTKEY)INVALID_HANDLE_VALUE)
|
||||||
|
return FALSE;
|
||||||
|
memcpy(pCryptKey->abKeyValue, pbKeyStream, *pKeyLen);
|
||||||
|
setup_key(pCryptKey);
|
||||||
|
if (dwFlags & CRYPT_EXPORTABLE)
|
||||||
|
pCryptKey->dwPermissions |= CRYPT_EXPORT;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* import_key [Internal]
|
* import_key [Internal]
|
||||||
*
|
*
|
||||||
|
@ -2871,6 +2952,8 @@ static BOOL import_key(HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDataLen,
|
||||||
pBlobHeader->bVersion != CUR_BLOB_VERSION ||
|
pBlobHeader->bVersion != CUR_BLOB_VERSION ||
|
||||||
pBlobHeader->reserved != 0)
|
pBlobHeader->reserved != 0)
|
||||||
{
|
{
|
||||||
|
TRACE("bVersion = %d, reserved = %d\n", pBlobHeader->bVersion,
|
||||||
|
pBlobHeader->reserved);
|
||||||
SetLastError(NTE_BAD_DATA);
|
SetLastError(NTE_BAD_DATA);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -2879,6 +2962,7 @@ static BOOL import_key(HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDataLen,
|
||||||
* fStoreKey's original value.
|
* fStoreKey's original value.
|
||||||
*/
|
*/
|
||||||
fStoreKey = fStoreKey && !(dwFlags & CRYPT_VERIFYCONTEXT);
|
fStoreKey = fStoreKey && !(dwFlags & CRYPT_VERIFYCONTEXT);
|
||||||
|
TRACE("blob type: %x\n", pBlobHeader->bType);
|
||||||
switch (pBlobHeader->bType)
|
switch (pBlobHeader->bType)
|
||||||
{
|
{
|
||||||
case PRIVATEKEYBLOB:
|
case PRIVATEKEYBLOB:
|
||||||
|
@ -2893,6 +2977,10 @@ static BOOL import_key(HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDataLen,
|
||||||
return import_symmetric_key(hProv, pbData, dwDataLen, hPubKey,
|
return import_symmetric_key(hProv, pbData, dwDataLen, hPubKey,
|
||||||
dwFlags, phKey);
|
dwFlags, phKey);
|
||||||
|
|
||||||
|
case PLAINTEXTKEYBLOB:
|
||||||
|
return import_plaintext_key(hProv, pbData, dwDataLen, dwFlags,
|
||||||
|
phKey);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
SetLastError(NTE_BAD_TYPE); /* FIXME: error code? */
|
SetLastError(NTE_BAD_TYPE); /* FIXME: error code? */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -2923,6 +3011,12 @@ BOOL WINAPI RSAENH_CPImportKey(HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDat
|
||||||
TRACE("(hProv=%08lx, pbData=%p, dwDataLen=%d, hPubKey=%08lx, dwFlags=%08x, phKey=%p)\n",
|
TRACE("(hProv=%08lx, pbData=%p, dwDataLen=%d, hPubKey=%08lx, dwFlags=%08x, phKey=%p)\n",
|
||||||
hProv, pbData, dwDataLen, hPubKey, dwFlags, phKey);
|
hProv, pbData, dwDataLen, hPubKey, dwFlags, phKey);
|
||||||
|
|
||||||
|
if (dwFlags & CRYPT_IPSEC_HMAC_KEY)
|
||||||
|
{
|
||||||
|
FIXME("unimplemented for CRYPT_IPSEC_HMAC_KEY\n");
|
||||||
|
SetLastError(NTE_BAD_FLAGS);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
return import_key(hProv, pbData, dwDataLen, hPubKey, dwFlags, TRUE, phKey);
|
return import_key(hProv, pbData, dwDataLen, hPubKey, dwFlags, TRUE, phKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2971,12 +3065,10 @@ BOOL WINAPI RSAENH_CPGenKey(HCRYPTPROV hProv, ALG_ID Algid, DWORD dwFlags, HCRYP
|
||||||
if (pCryptKey) {
|
if (pCryptKey) {
|
||||||
new_key_impl(pCryptKey->aiAlgid, &pCryptKey->context, pCryptKey->dwKeyLen);
|
new_key_impl(pCryptKey->aiAlgid, &pCryptKey->context, pCryptKey->dwKeyLen);
|
||||||
setup_key(pCryptKey);
|
setup_key(pCryptKey);
|
||||||
if (Algid == AT_SIGNATURE) {
|
|
||||||
RSAENH_CPDestroyKey(hProv, pKeyContainer->hSignatureKeyPair);
|
RSAENH_CPDestroyKey(hProv, pKeyContainer->hSignatureKeyPair);
|
||||||
copy_handle(&handle_table, *phKey, RSAENH_MAGIC_KEY,
|
copy_handle(&handle_table, *phKey, RSAENH_MAGIC_KEY,
|
||||||
&pKeyContainer->hSignatureKeyPair);
|
&pKeyContainer->hSignatureKeyPair);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AT_KEYEXCHANGE:
|
case AT_KEYEXCHANGE:
|
||||||
|
@ -2985,12 +3077,10 @@ BOOL WINAPI RSAENH_CPGenKey(HCRYPTPROV hProv, ALG_ID Algid, DWORD dwFlags, HCRYP
|
||||||
if (pCryptKey) {
|
if (pCryptKey) {
|
||||||
new_key_impl(pCryptKey->aiAlgid, &pCryptKey->context, pCryptKey->dwKeyLen);
|
new_key_impl(pCryptKey->aiAlgid, &pCryptKey->context, pCryptKey->dwKeyLen);
|
||||||
setup_key(pCryptKey);
|
setup_key(pCryptKey);
|
||||||
if (Algid == AT_KEYEXCHANGE) {
|
|
||||||
RSAENH_CPDestroyKey(hProv, pKeyContainer->hKeyExchangeKeyPair);
|
RSAENH_CPDestroyKey(hProv, pKeyContainer->hKeyExchangeKeyPair);
|
||||||
copy_handle(&handle_table, *phKey, RSAENH_MAGIC_KEY,
|
copy_handle(&handle_table, *phKey, RSAENH_MAGIC_KEY,
|
||||||
&pKeyContainer->hKeyExchangeKeyPair);
|
&pKeyContainer->hKeyExchangeKeyPair);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CALG_RC2:
|
case CALG_RC2:
|
||||||
|
@ -4371,7 +4461,8 @@ HRESULT WINAPI DllRegisterServer(void)
|
||||||
{
|
{
|
||||||
static const WCHAR szName[] = { 'N','a','m','e',0 };
|
static const WCHAR szName[] = { 'N','a','m','e',0 };
|
||||||
static const WCHAR szRSAName[3][54] = {
|
static const WCHAR szRSAName[3][54] = {
|
||||||
{ 'M','i','c','r','o','s','o','f','t',' ', 'B','a','s','e',' ',
|
{ 'M','i','c','r','o','s','o','f','t',' ',
|
||||||
|
'E','n','h','a','n','c','e','d',' ',
|
||||||
'C','r','y','p','t','o','g','r','a','p','h','i','c',' ',
|
'C','r','y','p','t','o','g','r','a','p','h','i','c',' ',
|
||||||
'P','r','o','v','i','d','e','r',' ','v','1','.','0',0 },
|
'P','r','o','v','i','d','e','r',' ','v','1','.','0',0 },
|
||||||
{ 'M','i','c','r','o','s','o','f','t',' ','R','S','A',' ',
|
{ 'M','i','c','r','o','s','o','f','t',' ','R','S','A',' ',
|
||||||
|
|
|
@ -85,6 +85,9 @@ typedef struct _SCHANNEL_ALG {
|
||||||
DWORD dwReserved;
|
DWORD dwReserved;
|
||||||
} SCHANNEL_ALG, *PSCHANNEL_ALG;
|
} SCHANNEL_ALG, *PSCHANNEL_ALG;
|
||||||
|
|
||||||
|
|
||||||
|
#define CRYPT_IPSEC_HMAC_KEY 0x0100
|
||||||
|
|
||||||
typedef struct _HMAC_INFO {
|
typedef struct _HMAC_INFO {
|
||||||
ALG_ID HashAlgid;
|
ALG_ID HashAlgid;
|
||||||
BYTE* pbInnerString;
|
BYTE* pbInnerString;
|
||||||
|
|
Loading…
Reference in a new issue