ReactOS 0.4.15-dev-7889-g76290a6
rsaenh.c File Reference
#include <config.h>
#include <wine/library.h>
#include <wine/debug.h>
#include <windef.h>
#include <winreg.h>
#include <wincrypt.h>
#include "handle.h"
#include "implglue.h"
#include <objbase.h>
#include <rpcproxy.h>
#include <aclapi.h>
#include <strsafe.h>
Include dependency graph for rsaenh.c:

Go to the source code of this file.

Classes

struct  _RSAENH_TLS1PRF_PARAMS
 
struct  tagCRYPTHASH
 
struct  _RSAENH_SCHANNEL_INFO
 
struct  tagCRYPTKEY
 
struct  tagKEYCONTAINER
 

Macros

#define WIN32_NO_STATUS
 
#define _INC_WINDOWS
 
#define COM_NO_WINDOWS_H
 
#define RSAENH_MAGIC_HASH   0x85938417u
 
#define RSAENH_MAX_HASH_SIZE   104
 
#define RSAENH_HASHSTATE_HASHING   1
 
#define RSAENH_HASHSTATE_FINISHED   2
 
#define RSAENH_MAGIC_KEY   0x73620457u
 
#define RSAENH_MAX_KEY_SIZE   64
 
#define RSAENH_MAX_BLOCK_SIZE   24
 
#define RSAENH_KEYSTATE_IDLE   0
 
#define RSAENH_KEYSTATE_ENCRYPTING   1
 
#define RSAENH_KEYSTATE_MASTERKEY   2
 
#define RSAENH_PERSONALITY_BASE   0u
 
#define RSAENH_PERSONALITY_STRONG   1u
 
#define RSAENH_PERSONALITY_ENHANCED   2u
 
#define RSAENH_PERSONALITY_SCHANNEL   3u
 
#define RSAENH_PERSONALITY_AES   4u
 
#define RSAENH_MAGIC_CONTAINER   0x26384993u
 
#define RSAENH_ENCRYPT   1
 
#define RSAENH_DECRYPT   0
 
#define RSAENH_HMAC_DEF_IPAD_CHAR   0x36
 
#define RSAENH_HMAC_DEF_OPAD_CHAR   0x5c
 
#define RSAENH_HMAC_DEF_PAD_LEN   64
 
#define RSAENH_HMAC_BLOCK_LEN   64
 
#define RSAENH_DES_EFFECTIVE_KEYLEN   56
 
#define RSAENH_DES_STORAGE_KEYLEN   64
 
#define RSAENH_3DES112_EFFECTIVE_KEYLEN   112
 
#define RSAENH_3DES112_STORAGE_KEYLEN   128
 
#define RSAENH_3DES_EFFECTIVE_KEYLEN   168
 
#define RSAENH_3DES_STORAGE_KEYLEN   192
 
#define RSAENH_MAGIC_RSA2   0x32415352
 
#define RSAENH_MAGIC_RSA1   0x31415352
 
#define RSAENH_PKC_BLOCKTYPE   0x02
 
#define RSAENH_SSL3_VERSION_MAJOR   3
 
#define RSAENH_SSL3_VERSION_MINOR   0
 
#define RSAENH_TLS1_VERSION_MAJOR   3
 
#define RSAENH_TLS1_VERSION_MINOR   1
 
#define RSAENH_REGKEY   "Software\\Wine\\Crypto\\RSA\\%s"
 
#define RSAENH_MIN(a, b)   ((a)<(b)?(a):(b))
 
#define RSAENH_MAX_ENUMALGS   24
 
#define RSAENH_PCT1_SSL2_SSL3_TLS1   (CRYPT_FLAG_PCT1|CRYPT_FLAG_SSL2|CRYPT_FLAG_SSL3|CRYPT_FLAG_TLS1)
 

Typedefs

typedef struct _RSAENH_TLS1PRF_PARAMS RSAENH_TLS1PRF_PARAMS
 
typedef struct tagCRYPTHASH CRYPTHASH
 
typedef struct _RSAENH_SCHANNEL_INFO RSAENH_SCHANNEL_INFO
 
typedef struct tagCRYPTKEY CRYPTKEY
 
typedef struct tagKEYCONTAINER KEYCONTAINER
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (crypt)
 
BOOL WINAPI RSAENH_CPGetKeyParam (HCRYPTPROV hProv, HCRYPTKEY hKey, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
 
BOOL WINAPI RSAENH_CPEncrypt (HCRYPTPROV hProv, HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen, DWORD dwBufLen)
 
BOOL WINAPI RSAENH_CPCreateHash (HCRYPTPROV hProv, ALG_ID Algid, HCRYPTKEY hKey, DWORD dwFlags, HCRYPTHASH *phHash)
 
BOOL WINAPI RSAENH_CPSetHashParam (HCRYPTPROV hProv, HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData, DWORD dwFlags)
 
BOOL WINAPI RSAENH_CPGetHashParam (HCRYPTPROV hProv, HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
 
BOOL WINAPI RSAENH_CPDestroyHash (HCRYPTPROV hProv, HCRYPTHASH hHash)
 
static BOOL crypt_export_key (CRYPTKEY *pCryptKey, HCRYPTKEY hPubKey, DWORD dwBlobType, DWORD dwFlags, BOOL force, BYTE *pbData, DWORD *pdwDataLen)
 
static BOOL import_key (HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, HCRYPTKEY hPubKey, DWORD dwFlags, BOOL fStoreKey, HCRYPTKEY *phKey)
 
BOOL WINAPI RSAENH_CPHashData (HCRYPTPROV hProv, HCRYPTHASH hHash, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
 
BOOL WINAPI DllMain (HINSTANCE hInstance, DWORD fdwReason, PVOID reserved)
 
static BOOL copy_param (BYTE *pbBuffer, DWORD *pdwBufferSize, const BYTE *pbParam, DWORD dwParamSize)
 
static KEYCONTAINERget_key_container (HCRYPTPROV hProv)
 
static const PROV_ENUMALGS_EXget_algid_info (HCRYPTPROV hProv, ALG_ID algid)
 
static BOOL copy_data_blob (PCRYPT_DATA_BLOB dst, const PCRYPT_DATA_BLOB src)
 
static BOOL concat_data_blobs (PCRYPT_DATA_BLOB dst, const PCRYPT_DATA_BLOB src1, const PCRYPT_DATA_BLOB src2)
 
static void free_data_blob (PCRYPT_DATA_BLOB pBlob)
 
static void init_data_blob (PCRYPT_DATA_BLOB pBlob)
 
static void free_hmac_info (PHMAC_INFO hmac_info)
 
static BOOL copy_hmac_info (PHMAC_INFO *dst, const HMAC_INFO *src)
 
static void destroy_hash (OBJECTHDR *pObject)
 
static BOOL init_hash (CRYPTHASH *pCryptHash)
 
static void update_hash (CRYPTHASH *pCryptHash, const BYTE *pbData, DWORD dwDataLen)
 
static void finalize_hash (CRYPTHASH *pCryptHash)
 
static void destroy_key (OBJECTHDR *pObject)
 
static void setup_key (CRYPTKEY *pCryptKey)
 
static HCRYPTKEY new_key (HCRYPTPROV hProv, ALG_ID aiAlgid, DWORD dwFlags, CRYPTKEY **ppCryptKey)
 
static LPCSTR map_key_spec_to_key_pair_name (DWORD dwKeySpec)
 
static void store_key_pair (HCRYPTKEY hCryptKey, HKEY hKey, DWORD dwKeySpec, DWORD dwFlags)
 
static LPCSTR map_key_spec_to_permissions_name (DWORD dwKeySpec)
 
static void store_key_permissions (HCRYPTKEY hCryptKey, HKEY hKey, DWORD dwKeySpec)
 
static BOOL create_container_key (KEYCONTAINER *pKeyContainer, REGSAM sam, HKEY *phKey)
 
static BOOL open_container_key (LPCSTR pszContainerName, DWORD dwFlags, REGSAM access, HKEY *phKey)
 
static BOOL delete_container_key (LPCSTR pszContainerName, DWORD dwFlags)
 
static void store_key_container_keys (KEYCONTAINER *pKeyContainer)
 
static void store_key_container_permissions (KEYCONTAINER *pKeyContainer)
 
static void release_key_container_keys (KEYCONTAINER *pKeyContainer)
 
static void destroy_key_container (OBJECTHDR *pObjectHdr)
 
static HCRYPTPROV new_key_container (PCCH pszContainerName, DWORD dwFlags, const VTableProvStruc *pVTable)
 
static BOOL read_key_value (HCRYPTPROV hKeyContainer, HKEY hKey, DWORD dwKeySpec, DWORD dwFlags, HCRYPTKEY *phCryptKey)
 
static HCRYPTPROV read_key_container (PCHAR pszContainerName, DWORD dwFlags, const VTableProvStruc *pVTable)
 
static BOOL build_hash_signature (BYTE *pbSignature, DWORD dwLen, ALG_ID aiAlgid, const BYTE *abHashValue, DWORD dwHashLen, DWORD dwFlags)
 
static BOOL tls1_p (HCRYPTHASH hHMAC, const PCRYPT_DATA_BLOB pblobSeed, BYTE *pbBuffer, DWORD dwBufferLen)
 
static BOOL tls1_prf (HCRYPTPROV hProv, HCRYPTPROV hSecret, const PCRYPT_DATA_BLOB pblobLabel, const PCRYPT_DATA_BLOB pblobSeed, BYTE *pbBuffer, DWORD dwBufferLen)
 
static BOOL pad_data (const BYTE *abData, DWORD dwDataLen, BYTE *abBuffer, DWORD dwBufferLen, DWORD dwFlags)
 
static BOOL unpad_data (const BYTE *abData, DWORD dwDataLen, BYTE *abBuffer, DWORD *dwBufferLen, DWORD dwFlags)
 
BOOL WINAPI RSAENH_CPAcquireContext (HCRYPTPROV *phProv, LPSTR pszContainer, DWORD dwFlags, PVTableProvStruc pVTable)
 
BOOL WINAPI RSAENH_CPDestroyKey (HCRYPTPROV hProv, HCRYPTKEY hKey)
 
BOOL WINAPI RSAENH_CPDuplicateHash (HCRYPTPROV hUID, HCRYPTHASH hHash, DWORD *pdwReserved, DWORD dwFlags, HCRYPTHASH *phHash)
 
BOOL WINAPI RSAENH_CPDuplicateKey (HCRYPTPROV hUID, HCRYPTKEY hKey, DWORD *pdwReserved, DWORD dwFlags, HCRYPTKEY *phKey)
 
BOOL WINAPI RSAENH_CPDecrypt (HCRYPTPROV hProv, HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen)
 
static BOOL crypt_export_simple (CRYPTKEY *pCryptKey, CRYPTKEY *pPubKey, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen)
 
static BOOL crypt_export_public_key (CRYPTKEY *pCryptKey, BYTE *pbData, DWORD *pdwDataLen)
 
static BOOL crypt_export_private_key (CRYPTKEY *pCryptKey, BOOL force, BYTE *pbData, DWORD *pdwDataLen)
 
static BOOL crypt_export_plaintext_key (CRYPTKEY *pCryptKey, BYTE *pbData, DWORD *pdwDataLen)
 
BOOL WINAPI RSAENH_CPExportKey (HCRYPTPROV hProv, HCRYPTKEY hKey, HCRYPTKEY hPubKey, DWORD dwBlobType, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen)
 
static void release_and_install_key (HCRYPTPROV hProv, HCRYPTKEY src, HCRYPTKEY *dest, DWORD fStoreKey)
 
static BOOL import_private_key (HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags, BOOL fStoreKey, HCRYPTKEY *phKey)
 
static BOOL import_public_key (HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags, HCRYPTKEY *phKey)
 
static BOOL import_symmetric_key (HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, HCRYPTKEY hPubKey, DWORD dwFlags, HCRYPTKEY *phKey)
 
static BOOL import_plaintext_key (HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags, HCRYPTKEY *phKey)
 
BOOL WINAPI RSAENH_CPImportKey (HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, HCRYPTKEY hPubKey, DWORD dwFlags, HCRYPTKEY *phKey)
 
BOOL WINAPI RSAENH_CPGenKey (HCRYPTPROV hProv, ALG_ID Algid, DWORD dwFlags, HCRYPTKEY *phKey)
 
BOOL WINAPI RSAENH_CPGenRandom (HCRYPTPROV hProv, DWORD dwLen, BYTE *pbBuffer)
 
BOOL WINAPI RSAENH_CPSetKeyParam (HCRYPTPROV hProv, HCRYPTKEY hKey, DWORD dwParam, BYTE *pbData, DWORD dwFlags)
 
BOOL WINAPI RSAENH_CPGetProvParam (HCRYPTPROV hProv, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
 
BOOL WINAPI RSAENH_CPDeriveKey (HCRYPTPROV hProv, ALG_ID Algid, HCRYPTHASH hBaseData, DWORD dwFlags, HCRYPTKEY *phKey)
 
BOOL WINAPI RSAENH_CPGetUserKey (HCRYPTPROV hProv, DWORD dwKeySpec, HCRYPTKEY *phUserKey)
 
BOOL WINAPI RSAENH_CPHashSessionKey (HCRYPTPROV hProv, HCRYPTHASH hHash, HCRYPTKEY hKey, DWORD dwFlags)
 
BOOL WINAPI RSAENH_CPReleaseContext (HCRYPTPROV hProv, DWORD dwFlags)
 
BOOL WINAPI RSAENH_CPSetProvParam (HCRYPTPROV hProv, DWORD dwParam, BYTE *pbData, DWORD dwFlags)
 
BOOL WINAPI RSAENH_CPSignHash (HCRYPTPROV hProv, HCRYPTHASH hHash, DWORD dwKeySpec, LPCWSTR sDescription, DWORD dwFlags, BYTE *pbSignature, DWORD *pdwSigLen)
 
BOOL WINAPI RSAENH_CPVerifySignature (HCRYPTPROV hProv, HCRYPTHASH hHash, const BYTE *pbSignature, DWORD dwSigLen, HCRYPTKEY hPubKey, LPCWSTR sDescription, DWORD dwFlags)
 
HRESULT WINAPI DllRegisterServer (void)
 
HRESULT WINAPI DllUnregisterServer (void)
 

Variables

static HINSTANCE instance
 
static const PROV_ENUMALGS_EX aProvEnumAlgsEx [5][RSAENH_MAX_ENUMALGS+1]
 
static struct handle_table handle_table
 

Macro Definition Documentation

◆ _INC_WINDOWS

#define _INC_WINDOWS

Definition at line 26 of file rsaenh.c.

◆ COM_NO_WINDOWS_H

#define COM_NO_WINDOWS_H

Definition at line 27 of file rsaenh.c.

◆ RSAENH_3DES112_EFFECTIVE_KEYLEN

#define RSAENH_3DES112_EFFECTIVE_KEYLEN   112

Definition at line 151 of file rsaenh.c.

◆ RSAENH_3DES112_STORAGE_KEYLEN

#define RSAENH_3DES112_STORAGE_KEYLEN   128

Definition at line 152 of file rsaenh.c.

◆ RSAENH_3DES_EFFECTIVE_KEYLEN

#define RSAENH_3DES_EFFECTIVE_KEYLEN   168

Definition at line 153 of file rsaenh.c.

◆ RSAENH_3DES_STORAGE_KEYLEN

#define RSAENH_3DES_STORAGE_KEYLEN   192

Definition at line 154 of file rsaenh.c.

◆ RSAENH_DECRYPT

#define RSAENH_DECRYPT   0

Definition at line 144 of file rsaenh.c.

◆ RSAENH_DES_EFFECTIVE_KEYLEN

#define RSAENH_DES_EFFECTIVE_KEYLEN   56

Definition at line 149 of file rsaenh.c.

◆ RSAENH_DES_STORAGE_KEYLEN

#define RSAENH_DES_STORAGE_KEYLEN   64

Definition at line 150 of file rsaenh.c.

◆ RSAENH_ENCRYPT

#define RSAENH_ENCRYPT   1

Definition at line 143 of file rsaenh.c.

◆ RSAENH_HASHSTATE_FINISHED

#define RSAENH_HASHSTATE_FINISHED   2

Definition at line 58 of file rsaenh.c.

◆ RSAENH_HASHSTATE_HASHING

#define RSAENH_HASHSTATE_HASHING   1

Definition at line 57 of file rsaenh.c.

◆ RSAENH_HMAC_BLOCK_LEN

#define RSAENH_HMAC_BLOCK_LEN   64

Definition at line 148 of file rsaenh.c.

◆ RSAENH_HMAC_DEF_IPAD_CHAR

#define RSAENH_HMAC_DEF_IPAD_CHAR   0x36

Definition at line 145 of file rsaenh.c.

◆ RSAENH_HMAC_DEF_OPAD_CHAR

#define RSAENH_HMAC_DEF_OPAD_CHAR   0x5c

Definition at line 146 of file rsaenh.c.

◆ RSAENH_HMAC_DEF_PAD_LEN

#define RSAENH_HMAC_DEF_PAD_LEN   64

Definition at line 147 of file rsaenh.c.

◆ RSAENH_KEYSTATE_ENCRYPTING

#define RSAENH_KEYSTATE_ENCRYPTING   1

Definition at line 86 of file rsaenh.c.

◆ RSAENH_KEYSTATE_IDLE

#define RSAENH_KEYSTATE_IDLE   0

Definition at line 85 of file rsaenh.c.

◆ RSAENH_KEYSTATE_MASTERKEY

#define RSAENH_KEYSTATE_MASTERKEY   2

Definition at line 87 of file rsaenh.c.

◆ RSAENH_MAGIC_CONTAINER

#define RSAENH_MAGIC_CONTAINER   0x26384993u

Definition at line 126 of file rsaenh.c.

◆ RSAENH_MAGIC_HASH

#define RSAENH_MAGIC_HASH   0x85938417u

Definition at line 55 of file rsaenh.c.

◆ RSAENH_MAGIC_KEY

#define RSAENH_MAGIC_KEY   0x73620457u

Definition at line 82 of file rsaenh.c.

◆ RSAENH_MAGIC_RSA1

#define RSAENH_MAGIC_RSA1   0x31415352

Definition at line 156 of file rsaenh.c.

◆ RSAENH_MAGIC_RSA2

#define RSAENH_MAGIC_RSA2   0x32415352

Definition at line 155 of file rsaenh.c.

◆ RSAENH_MAX_BLOCK_SIZE

#define RSAENH_MAX_BLOCK_SIZE   24

Definition at line 84 of file rsaenh.c.

◆ RSAENH_MAX_ENUMALGS

#define RSAENH_MAX_ENUMALGS   24

Definition at line 168 of file rsaenh.c.

◆ RSAENH_MAX_HASH_SIZE

#define RSAENH_MAX_HASH_SIZE   104

Definition at line 56 of file rsaenh.c.

◆ RSAENH_MAX_KEY_SIZE

#define RSAENH_MAX_KEY_SIZE   64

Definition at line 83 of file rsaenh.c.

◆ RSAENH_MIN

#define RSAENH_MIN (   a,
  b 
)    ((a)<(b)?(a):(b))

Definition at line 164 of file rsaenh.c.

◆ RSAENH_PCT1_SSL2_SSL3_TLS1

Definition at line 169 of file rsaenh.c.

◆ RSAENH_PERSONALITY_AES

#define RSAENH_PERSONALITY_AES   4u

Definition at line 124 of file rsaenh.c.

◆ RSAENH_PERSONALITY_BASE

#define RSAENH_PERSONALITY_BASE   0u

Definition at line 120 of file rsaenh.c.

◆ RSAENH_PERSONALITY_ENHANCED

#define RSAENH_PERSONALITY_ENHANCED   2u

Definition at line 122 of file rsaenh.c.

◆ RSAENH_PERSONALITY_SCHANNEL

#define RSAENH_PERSONALITY_SCHANNEL   3u

Definition at line 123 of file rsaenh.c.

◆ RSAENH_PERSONALITY_STRONG

#define RSAENH_PERSONALITY_STRONG   1u

Definition at line 121 of file rsaenh.c.

◆ RSAENH_PKC_BLOCKTYPE

#define RSAENH_PKC_BLOCKTYPE   0x02

Definition at line 157 of file rsaenh.c.

◆ RSAENH_REGKEY

#define RSAENH_REGKEY   "Software\\Wine\\Crypto\\RSA\\%s"

Definition at line 162 of file rsaenh.c.

◆ RSAENH_SSL3_VERSION_MAJOR

#define RSAENH_SSL3_VERSION_MAJOR   3

Definition at line 158 of file rsaenh.c.

◆ RSAENH_SSL3_VERSION_MINOR

#define RSAENH_SSL3_VERSION_MINOR   0

Definition at line 159 of file rsaenh.c.

◆ RSAENH_TLS1_VERSION_MAJOR

#define RSAENH_TLS1_VERSION_MAJOR   3

Definition at line 160 of file rsaenh.c.

◆ RSAENH_TLS1_VERSION_MINOR

#define RSAENH_TLS1_VERSION_MINOR   1

Definition at line 161 of file rsaenh.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 25 of file rsaenh.c.

Typedef Documentation

◆ CRYPTHASH

◆ CRYPTKEY

◆ KEYCONTAINER

◆ RSAENH_SCHANNEL_INFO

◆ RSAENH_TLS1PRF_PARAMS

Function Documentation

◆ build_hash_signature()

static BOOL build_hash_signature ( BYTE pbSignature,
DWORD  dwLen,
ALG_ID  aiAlgid,
const BYTE abHashValue,
DWORD  dwHashLen,
DWORD  dwFlags 
)
static

Definition at line 1469 of file rsaenh.c.

1471{
1472 /* These prefixes are meant to be concatenated with hash values of the
1473 * respective kind to form a PKCS #7 DigestInfo. */
1474 static const struct tagOIDDescriptor {
1475 ALG_ID aiAlgid;
1476 DWORD dwLen;
1477 const BYTE abOID[19];
1478 } aOIDDescriptor[] = {
1479 { CALG_MD2, 18, { 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48,
1480 0x86, 0xf7, 0x0d, 0x02, 0x02, 0x05, 0x00, 0x04, 0x10 } },
1481 { CALG_MD4, 18, { 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48,
1482 0x86, 0xf7, 0x0d, 0x02, 0x04, 0x05, 0x00, 0x04, 0x10 } },
1483 { CALG_MD5, 18, { 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48,
1484 0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10 } },
1485 { CALG_SHA, 15, { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03,
1486 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 } },
1487 { CALG_SHA_256, 19, { 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
1488 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01,
1489 0x05, 0x00, 0x04, 0x20 } },
1490 { CALG_SHA_384, 19, { 0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
1491 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02,
1492 0x05, 0x00, 0x04, 0x30 } },
1493 { CALG_SHA_512, 19, { 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
1494 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03,
1495 0x05, 0x00, 0x04, 0x40 } },
1496 { CALG_SSL3_SHAMD5, 0, { 0 } },
1497 { 0, 0, { 0 } }
1498 };
1499 DWORD dwIdxOID, i, j;
1500
1501 for (dwIdxOID = 0; aOIDDescriptor[dwIdxOID].aiAlgid; dwIdxOID++) {
1502 if (aOIDDescriptor[dwIdxOID].aiAlgid == aiAlgid) break;
1503 }
1504
1505 if (!aOIDDescriptor[dwIdxOID].aiAlgid) {
1507 return FALSE;
1508 }
1509
1510 /* Build the padded signature */
1511 if (dwFlags & CRYPT_X931_FORMAT) {
1512 pbSignature[0] = 0x6b;
1513 for (i=1; i < dwLen - dwHashLen - 3; i++) {
1514 pbSignature[i] = 0xbb;
1515 }
1516 pbSignature[i++] = 0xba;
1517 for (j=0; j < dwHashLen; j++, i++) {
1518 pbSignature[i] = abHashValue[j];
1519 }
1520 pbSignature[i++] = 0x33;
1521 pbSignature[i++] = 0xcc;
1522 } else {
1523 pbSignature[0] = 0x00;
1524 pbSignature[1] = 0x01;
1525 if (dwFlags & CRYPT_NOHASHOID) {
1526 for (i=2; i < dwLen - 1 - dwHashLen; i++) {
1527 pbSignature[i] = 0xff;
1528 }
1529 pbSignature[i++] = 0x00;
1530 } else {
1531 for (i=2; i < dwLen - 1 - aOIDDescriptor[dwIdxOID].dwLen - dwHashLen; i++) {
1532 pbSignature[i] = 0xff;
1533 }
1534 pbSignature[i++] = 0x00;
1535 for (j=0; j < aOIDDescriptor[dwIdxOID].dwLen; j++) {
1536 pbSignature[i++] = aOIDDescriptor[dwIdxOID].abOID[j];
1537 }
1538 }
1539 for (j=0; j < dwHashLen; j++) {
1540 pbSignature[i++] = abHashValue[j];
1541 }
1542 }
1543
1544 return TRUE;
1545}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define SetLastError(x)
Definition: compat.h:752
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define CRYPT_X931_FORMAT
Definition: wincrypt.h:2179
#define CALG_SHA_384
Definition: wincrypt.h:1814
#define CALG_MD5
Definition: wincrypt.h:1805
#define CALG_SHA_256
Definition: wincrypt.h:1813
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
#define CRYPT_NOHASHOID
Definition: wincrypt.h:2177
#define CALG_MD2
Definition: wincrypt.h:1803
#define CALG_MD4
Definition: wincrypt.h:1804
#define CALG_SSL3_SHAMD5
Definition: wincrypt.h:1809
#define CALG_SHA
Definition: wincrypt.h:1806
#define CALG_SHA_512
Definition: wincrypt.h:1815
unsigned int ALG_ID
Definition: wincrypt.h:45
#define NTE_BAD_ALGID
Definition: winerror.h:2876
unsigned char BYTE
Definition: xxhash.c:193

Referenced by RSAENH_CPSignHash(), and RSAENH_CPVerifySignature().

◆ concat_data_blobs()

static BOOL concat_data_blobs ( PCRYPT_DATA_BLOB  dst,
const PCRYPT_DATA_BLOB  src1,
const PCRYPT_DATA_BLOB  src2 
)
inlinestatic

Definition at line 505 of file rsaenh.c.

507{
508 dst->cbData = src1->cbData + src2->cbData;
509 dst->pbData = HeapAlloc(GetProcessHeap(), 0, dst->cbData);
510 if (!dst->pbData) {
512 return FALSE;
513 }
514 memcpy(dst->pbData, src1->pbData, src1->cbData);
515 memcpy(dst->pbData + src1->cbData, src2->pbData, src2->cbData);
516 return TRUE;
517}
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
GLenum GLenum dst
Definition: glext.h:6340
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
BYTE * pbData
Definition: wincrypt.h:103
#define NTE_NO_MEMORY
Definition: winerror.h:2882

Referenced by RSAENH_CPCreateHash(), and tls1_prf().

◆ copy_data_blob()

static BOOL copy_data_blob ( PCRYPT_DATA_BLOB  dst,
const PCRYPT_DATA_BLOB  src 
)
inlinestatic

Definition at line 476 of file rsaenh.c.

477{
478 dst->pbData = HeapAlloc(GetProcessHeap(), 0, src->cbData);
479 if (!dst->pbData) {
481 return FALSE;
482 }
483 dst->cbData = src->cbData;
484 memcpy(dst->pbData, src->pbData, src->cbData);
485 return TRUE;
486}
GLenum src
Definition: glext.h:6340

Referenced by import_plaintext_key(), RSAENH_CPDuplicateHash(), RSAENH_CPDuplicateKey(), RSAENH_CPSetHashParam(), and RSAENH_CPSetKeyParam().

◆ copy_hmac_info()

static BOOL copy_hmac_info ( PHMAC_INFO dst,
const HMAC_INFO src 
)
static

Definition at line 573 of file rsaenh.c.

573 {
574 if (!src) return FALSE;
575 *dst = HeapAlloc(GetProcessHeap(), 0, sizeof(HMAC_INFO));
576 if (!*dst) return FALSE;
577 **dst = *src;
578 (*dst)->pbInnerString = NULL;
579 (*dst)->pbOuterString = NULL;
580 if ((*dst)->cbInnerString == 0) (*dst)->cbInnerString = RSAENH_HMAC_DEF_PAD_LEN;
581 (*dst)->pbInnerString = HeapAlloc(GetProcessHeap(), 0, (*dst)->cbInnerString);
582 if (!(*dst)->pbInnerString) {
584 return FALSE;
585 }
586 if (src->cbInnerString)
587 memcpy((*dst)->pbInnerString, src->pbInnerString, src->cbInnerString);
588 else
590 if ((*dst)->cbOuterString == 0) (*dst)->cbOuterString = RSAENH_HMAC_DEF_PAD_LEN;
591 (*dst)->pbOuterString = HeapAlloc(GetProcessHeap(), 0, (*dst)->cbOuterString);
592 if (!(*dst)->pbOuterString) {
594 return FALSE;
595 }
596 if (src->cbOuterString)
597 memcpy((*dst)->pbOuterString, src->pbOuterString, src->cbOuterString);
598 else
600 return TRUE;
601}
#define NULL
Definition: types.h:112
#define RSAENH_HMAC_DEF_OPAD_CHAR
Definition: rsaenh.c:146
#define RSAENH_HMAC_DEF_IPAD_CHAR
Definition: rsaenh.c:145
static void free_hmac_info(PHMAC_INFO hmac_info)
Definition: rsaenh.c:550
#define RSAENH_HMAC_DEF_PAD_LEN
Definition: rsaenh.c:147
#define memset(x, y, z)
Definition: compat.h:39

Referenced by RSAENH_CPDuplicateHash(), and RSAENH_CPSetHashParam().

◆ copy_param()

static BOOL copy_param ( BYTE pbBuffer,
DWORD pdwBufferSize,
const BYTE pbParam,
DWORD  dwParamSize 
)
inlinestatic

Definition at line 403 of file rsaenh.c.

405{
406 if (pbBuffer)
407 {
408 if (dwParamSize > *pdwBufferSize)
409 {
411 *pdwBufferSize = dwParamSize;
412 return FALSE;
413 }
414 memcpy(pbBuffer, pbParam, dwParamSize);
415 }
416 *pdwBufferSize = dwParamSize;
417 return TRUE;
418}
#define ERROR_MORE_DATA
Definition: dderror.h:13

Referenced by RSAENH_CPGetHashParam(), RSAENH_CPGetKeyParam(), and RSAENH_CPGetProvParam().

◆ create_container_key()

static BOOL create_container_key ( KEYCONTAINER pKeyContainer,
REGSAM  sam,
HKEY phKey 
)
static

Definition at line 1103 of file rsaenh.c.

1104{
1105 CHAR szRSABase[MAX_PATH];
1106 HKEY hRootKey;
1107
1108 StringCbPrintfA(szRSABase, sizeof(szRSABase), RSAENH_REGKEY, pKeyContainer->szName);
1109
1110 if (pKeyContainer->dwFlags & CRYPT_MACHINE_KEYSET)
1111 hRootKey = HKEY_LOCAL_MACHINE;
1112 else
1113 hRootKey = HKEY_CURRENT_USER;
1114
1115 /* @@ Wine registry key: HKLM\Software\Wine\Crypto\RSA */
1116 /* @@ Wine registry key: HKCU\Software\Wine\Crypto\RSA */
1117 return RegCreateKeyExA(hRootKey, szRSABase, 0, NULL,
1119 == ERROR_SUCCESS;
1120}
static REGSAM sam
Definition: query.c:143
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegCreateKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD Reserved, _In_ LPSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_ LPDWORD lpdwDisposition)
Definition: reg.c:1034
#define MAX_PATH
Definition: compat.h:34
#define RSAENH_REGKEY
Definition: rsaenh.c:162
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
STRSAFEAPI StringCbPrintfA(STRSAFE_LPSTR pszDest, size_t cbDest, STRSAFE_LPCSTR pszFormat,...)
Definition: strsafe.h:547
CHAR szName[MAX_PATH]
Definition: rsaenh.c:134
DWORD dwFlags
Definition: rsaenh.c:130
#define CRYPT_MACHINE_KEYSET
Definition: wincrypt.h:2072
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define HKEY_CURRENT_USER
Definition: winreg.h:11
char CHAR
Definition: xmlstorage.h:175

Referenced by new_key_container(), store_key_container_keys(), and store_key_container_permissions().

◆ crypt_export_key()

static BOOL crypt_export_key ( CRYPTKEY pCryptKey,
HCRYPTKEY  hPubKey,
DWORD  dwBlobType,
DWORD  dwFlags,
BOOL  force,
BYTE pbData,
DWORD pdwDataLen 
)
static

Definition at line 2621 of file rsaenh.c.

2624{
2625 CRYPTKEY *pPubKey;
2626
2628 if (pCryptKey->aiAlgid != CALG_SSL2_MASTER) {
2630 return FALSE;
2631 }
2632 }
2633
2634 switch ((BYTE)dwBlobType)
2635 {
2636 case SIMPLEBLOB:
2637 if (!lookup_handle(&handle_table, hPubKey, RSAENH_MAGIC_KEY, (OBJECTHDR**)&pPubKey)){
2638 SetLastError(NTE_BAD_PUBLIC_KEY); /* FIXME: error_code? */
2639 return FALSE;
2640 }
2641 return crypt_export_simple(pCryptKey, pPubKey, dwFlags, pbData,
2642 pdwDataLen);
2643
2644 case PUBLICKEYBLOB:
2646 SetLastError(NTE_BAD_KEY); /* FIXME: error code? */
2647 return FALSE;
2648 }
2649
2650 return crypt_export_public_key(pCryptKey, pbData, pdwDataLen);
2651
2652 case PRIVATEKEYBLOB:
2653 return crypt_export_private_key(pCryptKey, force, pbData, pdwDataLen);
2654
2655 case PLAINTEXTKEYBLOB:
2656 return crypt_export_plaintext_key(pCryptKey, pbData, pdwDataLen);
2657
2658 default:
2659 SetLastError(NTE_BAD_TYPE); /* FIXME: error code? */
2660 return FALSE;
2661 }
2662}
BOOL lookup_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType, OBJECTHDR **lplpObject)
Definition: handle.c:275
BOOL is_valid_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType)
Definition: handle.c:96
static BOOL crypt_export_simple(CRYPTKEY *pCryptKey, CRYPTKEY *pPubKey, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen)
Definition: rsaenh.c:2457
static BOOL crypt_export_private_key(CRYPTKEY *pCryptKey, BOOL force, BYTE *pbData, DWORD *pdwDataLen)
Definition: rsaenh.c:2532
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:82
static BOOL crypt_export_public_key(CRYPTKEY *pCryptKey, BYTE *pbData, DWORD *pdwDataLen)
Definition: rsaenh.c:2497
static BOOL crypt_export_plaintext_key(CRYPTKEY *pCryptKey, BYTE *pbData, DWORD *pdwDataLen)
Definition: rsaenh.c:2573
ALG_ID aiAlgid
Definition: rsaenh.c:99
#define PLAINTEXTKEYBLOB
Definition: wincrypt.h:2242
#define CALG_SSL2_MASTER
Definition: wincrypt.h:1848
#define PRIVATEKEYBLOB
Definition: wincrypt.h:2241
#define PUBLICKEYBLOB
Definition: wincrypt.h:2240
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201
#define SIMPLEBLOB
Definition: wincrypt.h:2239
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE _Inout_ DWORD * pdwDataLen
Definition: wincrypt.h:4202
#define CRYPT_SSL2_FALLBACK
Definition: wincrypt.h:2216
#define NTE_BAD_PUBLIC_KEY
Definition: winerror.h:2889
#define NTE_BAD_KEY
Definition: winerror.h:2871
#define NTE_BAD_TYPE
Definition: winerror.h:2878

Referenced by RSAENH_CPExportKey(), and store_key_pair().

◆ crypt_export_plaintext_key()

static BOOL crypt_export_plaintext_key ( CRYPTKEY pCryptKey,
BYTE pbData,
DWORD pdwDataLen 
)
static

Definition at line 2573 of file rsaenh.c.

2575{
2576 BLOBHEADER *pBlobHeader = (BLOBHEADER*)pbData;
2577 DWORD *pKeyLen = (DWORD*)(pBlobHeader+1);
2578 BYTE *pbKey = (BYTE*)(pKeyLen+1);
2579 DWORD dwDataLen;
2580
2581 dwDataLen = sizeof(BLOBHEADER) + sizeof(DWORD) + pCryptKey->dwKeyLen;
2582 if (pbData) {
2583 if (*pdwDataLen < dwDataLen) {
2585 *pdwDataLen = dwDataLen;
2586 return FALSE;
2587 }
2588
2589 pBlobHeader->bType = PLAINTEXTKEYBLOB;
2590 pBlobHeader->bVersion = CUR_BLOB_VERSION;
2591 pBlobHeader->reserved = 0;
2592 pBlobHeader->aiKeyAlg = pCryptKey->aiAlgid;
2593
2594 *pKeyLen = pCryptKey->dwKeyLen;
2595 memcpy(pbKey, pCryptKey->abKeyValue, pCryptKey->dwKeyLen);
2596 }
2597 *pdwDataLen = dwDataLen;
2598 return TRUE;
2599}
ALG_ID aiKeyAlg
Definition: wincrypt.h:139
BYTE abKeyValue[RSAENH_MAX_KEY_SIZE]
Definition: rsaenh.c:110
DWORD dwKeyLen
Definition: rsaenh.c:104
struct _PUBLICKEYSTRUC BLOBHEADER
#define CUR_BLOB_VERSION
Definition: wincrypt.h:2247

Referenced by crypt_export_key().

◆ crypt_export_private_key()

static BOOL crypt_export_private_key ( CRYPTKEY pCryptKey,
BOOL  force,
BYTE pbData,
DWORD pdwDataLen 
)
static

Definition at line 2532 of file rsaenh.c.

2534{
2535 BLOBHEADER *pBlobHeader = (BLOBHEADER*)pbData;
2536 RSAPUBKEY *pRSAPubKey = (RSAPUBKEY*)(pBlobHeader+1);
2537 DWORD dwDataLen;
2538
2539 if ((pCryptKey->aiAlgid != CALG_RSA_KEYX) && (pCryptKey->aiAlgid != CALG_RSA_SIGN)) {
2541 return FALSE;
2542 }
2543 if (!force && !(pCryptKey->dwPermissions & CRYPT_EXPORT))
2544 {
2546 return FALSE;
2547 }
2548
2549 dwDataLen = sizeof(BLOBHEADER) + sizeof(RSAPUBKEY) +
2550 2 * pCryptKey->dwKeyLen + 5 * ((pCryptKey->dwKeyLen + 1) >> 1);
2551 if (pbData) {
2552 if (*pdwDataLen < dwDataLen) {
2554 *pdwDataLen = dwDataLen;
2555 return FALSE;
2556 }
2557
2558 pBlobHeader->bType = PRIVATEKEYBLOB;
2559 pBlobHeader->bVersion = CUR_BLOB_VERSION;
2560 pBlobHeader->reserved = 0;
2561 pBlobHeader->aiKeyAlg = pCryptKey->aiAlgid;
2562
2563 pRSAPubKey->magic = RSAENH_MAGIC_RSA2;
2564 pRSAPubKey->bitlen = pCryptKey->dwKeyLen << 3;
2565
2566 export_private_key_impl((BYTE*)(pRSAPubKey+1), &pCryptKey->context,
2567 pCryptKey->dwKeyLen, &pRSAPubKey->pubexp);
2568 }
2569 *pdwDataLen = dwDataLen;
2570 return TRUE;
2571}
#define RSAENH_MAGIC_RSA2
Definition: rsaenh.c:155
BOOL export_private_key_impl(BYTE *pbDest, const KEY_CONTEXT *pKeyContext, DWORD dwKeyLen, DWORD *pdwPubExp)
Definition: implglue.c:438
DWORD pubexp
Definition: wincrypt.h:145
DWORD bitlen
Definition: wincrypt.h:144
DWORD magic
Definition: wincrypt.h:143
DWORD dwPermissions
Definition: rsaenh.c:103
KEY_CONTEXT context
Definition: rsaenh.c:109
#define CALG_RSA_SIGN
Definition: wincrypt.h:1816
#define CRYPT_EXPORT
Definition: wincrypt.h:2197
#define CALG_RSA_KEYX
Definition: wincrypt.h:1824
#define NTE_BAD_KEY_STATE
Definition: winerror.h:2879

Referenced by crypt_export_key().

◆ crypt_export_public_key()

static BOOL crypt_export_public_key ( CRYPTKEY pCryptKey,
BYTE pbData,
DWORD pdwDataLen 
)
static

Definition at line 2497 of file rsaenh.c.

2499{
2500 BLOBHEADER *pBlobHeader = (BLOBHEADER*)pbData;
2501 RSAPUBKEY *pRSAPubKey = (RSAPUBKEY*)(pBlobHeader+1);
2502 DWORD dwDataLen;
2503
2504 if ((pCryptKey->aiAlgid != CALG_RSA_KEYX) && (pCryptKey->aiAlgid != CALG_RSA_SIGN)) {
2506 return FALSE;
2507 }
2508
2509 dwDataLen = sizeof(BLOBHEADER) + sizeof(RSAPUBKEY) + pCryptKey->dwKeyLen;
2510 if (pbData) {
2511 if (*pdwDataLen < dwDataLen) {
2513 *pdwDataLen = dwDataLen;
2514 return FALSE;
2515 }
2516
2517 pBlobHeader->bType = PUBLICKEYBLOB;
2518 pBlobHeader->bVersion = CUR_BLOB_VERSION;
2519 pBlobHeader->reserved = 0;
2520 pBlobHeader->aiKeyAlg = pCryptKey->aiAlgid;
2521
2522 pRSAPubKey->magic = RSAENH_MAGIC_RSA1;
2523 pRSAPubKey->bitlen = pCryptKey->dwKeyLen << 3;
2524
2525 export_public_key_impl((BYTE*)(pRSAPubKey+1), &pCryptKey->context,
2526 pCryptKey->dwKeyLen, &pRSAPubKey->pubexp);
2527 }
2528 *pdwDataLen = dwDataLen;
2529 return TRUE;
2530}
#define RSAENH_MAGIC_RSA1
Definition: rsaenh.c:156
BOOL export_public_key_impl(BYTE *pbDest, const KEY_CONTEXT *pKeyContext, DWORD dwKeyLen, DWORD *pdwPubExp)
Definition: implglue.c:401

Referenced by crypt_export_key().

◆ crypt_export_simple()

static BOOL crypt_export_simple ( CRYPTKEY pCryptKey,
CRYPTKEY pPubKey,
DWORD  dwFlags,
BYTE pbData,
DWORD pdwDataLen 
)
static

Definition at line 2457 of file rsaenh.c.

2459{
2460 BLOBHEADER *pBlobHeader = (BLOBHEADER*)pbData;
2461 ALG_ID *pAlgid = (ALG_ID*)(pBlobHeader+1);
2462 DWORD dwDataLen;
2463
2465 SetLastError(NTE_BAD_KEY); /* FIXME: error code? */
2466 return FALSE;
2467 }
2468
2469 dwDataLen = sizeof(BLOBHEADER) + sizeof(ALG_ID) + pPubKey->dwBlockLen;
2470 if (pbData) {
2471 if (*pdwDataLen < dwDataLen) {
2473 *pdwDataLen = dwDataLen;
2474 return FALSE;
2475 }
2476
2477 pBlobHeader->bType = SIMPLEBLOB;
2478 pBlobHeader->bVersion = CUR_BLOB_VERSION;
2479 pBlobHeader->reserved = 0;
2480 pBlobHeader->aiKeyAlg = pCryptKey->aiAlgid;
2481
2482 *pAlgid = pPubKey->aiAlgid;
2483
2484 if (!pad_data(pCryptKey->abKeyValue, pCryptKey->dwKeyLen, (BYTE*)(pAlgid+1),
2485 pPubKey->dwBlockLen, dwFlags))
2486 {
2487 return FALSE;
2488 }
2489
2490 encrypt_block_impl(pPubKey->aiAlgid, PK_PUBLIC, &pPubKey->context, (BYTE*)(pAlgid+1),
2491 (BYTE*)(pAlgid+1), RSAENH_ENCRYPT);
2492 }
2493 *pdwDataLen = dwDataLen;
2494 return TRUE;
2495}
static BOOL pad_data(const BYTE *abData, DWORD dwDataLen, BYTE *abBuffer, DWORD dwBufferLen, DWORD dwFlags)
Definition: rsaenh.c:1693
#define RSAENH_ENCRYPT
Definition: rsaenh.c:143
#define PK_PUBLIC
Definition: tomcrypt.h:450
BOOL encrypt_block_impl(ALG_ID aiAlgid, DWORD dwKeySpec, KEY_CONTEXT *pKeyContext, const BYTE *in, BYTE *out, DWORD enc)
Definition: implglue.c:303
DWORD dwBlockLen
Definition: rsaenh.c:107
#define ALG_CLASS_MSG_ENCRYPT
Definition: wincrypt.h:1716
#define ALG_CLASS_DATA_ENCRYPT
Definition: wincrypt.h:1717
#define GET_ALG_CLASS(x)
Definition: wincrypt.h:1709

Referenced by crypt_export_key().

◆ delete_container_key()

static BOOL delete_container_key ( LPCSTR  pszContainerName,
DWORD  dwFlags 
)
static

Definition at line 1161 of file rsaenh.c.

1162{
1163 CHAR szRegKey[MAX_PATH];
1164
1165 if (snprintf(szRegKey, MAX_PATH, RSAENH_REGKEY, pszContainerName) >= MAX_PATH) {
1167 return FALSE;
1168 } else {
1169 HKEY hRootKey;
1171 hRootKey = HKEY_LOCAL_MACHINE;
1172 else
1173 hRootKey = HKEY_CURRENT_USER;
1174 if (!RegDeleteKeyA(hRootKey, szRegKey)) {
1176 return TRUE;
1177 } else {
1179 return FALSE;
1180 }
1181 }
1182}
LONG WINAPI RegDeleteKeyA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey)
Definition: reg.c:1224
#define NTE_BAD_KEYSET_PARAM
Definition: winerror.h:2899
#define NTE_BAD_KEYSET
Definition: winerror.h:2890
#define snprintf
Definition: wintirpc.h:48

Referenced by RSAENH_CPAcquireContext().

◆ destroy_hash()

static void destroy_hash ( OBJECTHDR pObject)
static

Definition at line 612 of file rsaenh.c.

613{
614 CRYPTHASH *pCryptHash = (CRYPTHASH*)pObject;
615
616 free_hmac_info(pCryptHash->pHMACInfo);
618 free_data_blob(&pCryptHash->tpPRFParams.blobSeed);
619 HeapFree(GetProcessHeap(), 0, pCryptHash);
620}
#define HeapFree(x, y, z)
Definition: compat.h:735
static void free_data_blob(PCRYPT_DATA_BLOB pBlob)
Definition: rsaenh.c:527
FxObject * pObject
CRYPT_DATA_BLOB blobSeed
Definition: rsaenh.c:62
CRYPT_DATA_BLOB blobLabel
Definition: rsaenh.c:61
RSAENH_TLS1PRF_PARAMS tpPRFParams
Definition: rsaenh.c:76
PHMAC_INFO pHMACInfo
Definition: rsaenh.c:75

Referenced by RSAENH_CPCreateHash(), and RSAENH_CPDuplicateHash().

◆ destroy_key()

static void destroy_key ( OBJECTHDR pObject)
static

Definition at line 749 of file rsaenh.c.

750{
751 CRYPTKEY *pCryptKey = (CRYPTKEY*)pObject;
752
753 free_key_impl(pCryptKey->aiAlgid, &pCryptKey->context);
756 free_data_blob(&pCryptKey->blobHmacKey);
757 HeapFree(GetProcessHeap(), 0, pCryptKey);
758}
BOOL free_key_impl(ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext)
Definition: implglue.c:197
CRYPT_DATA_BLOB blobServerRandom
Definition: rsaenh.c:93
CRYPT_DATA_BLOB blobClientRandom
Definition: rsaenh.c:92
CRYPT_DATA_BLOB blobHmacKey
Definition: rsaenh.c:114
RSAENH_SCHANNEL_INFO siSChannelInfo
Definition: rsaenh.c:113

Referenced by new_key(), and RSAENH_CPDuplicateKey().

◆ destroy_key_container()

static void destroy_key_container ( OBJECTHDR pObjectHdr)
static

Definition at line 1263 of file rsaenh.c.

1264{
1265 KEYCONTAINER *pKeyContainer = (KEYCONTAINER*)pObjectHdr;
1266
1267 if (!(pKeyContainer->dwFlags & CRYPT_VERIFYCONTEXT))
1268 {
1269 store_key_container_keys(pKeyContainer);
1270 store_key_container_permissions(pKeyContainer);
1271 release_key_container_keys(pKeyContainer);
1272 }
1273 else
1274 release_key_container_keys(pKeyContainer);
1275 HeapFree( GetProcessHeap(), 0, pKeyContainer );
1276}
static void release_key_container_keys(KEYCONTAINER *pKeyContainer)
Definition: rsaenh.c:1247
static void store_key_container_permissions(KEYCONTAINER *pKeyContainer)
Definition: rsaenh.c:1225
static void store_key_container_keys(KEYCONTAINER *pKeyContainer)
Definition: rsaenh.c:1192
#define CRYPT_VERIFYCONTEXT
Definition: wincrypt.h:2069

Referenced by new_key_container().

◆ DllMain()

BOOL WINAPI DllMain ( HINSTANCE  hInstance,
DWORD  fdwReason,
PVOID  reserved 
)

Definition at line 367 of file rsaenh.c.

368{
369 switch (fdwReason)
370 {
375 break;
376
378 if (reserved) break;
380 break;
381 }
382 return TRUE;
383}
HINSTANCE hInstance
Definition: charmap.c:19
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
void destroy_handle_table(struct handle_table *lpTable)
Definition: handle.c:72
void init_handle_table(struct handle_table *lpTable)
Definition: handle.c:53
static HINSTANCE instance
Definition: rsaenh.c:50
r reserved
Definition: btrfs.c:3006

◆ DllRegisterServer()

HRESULT WINAPI DllRegisterServer ( void  )

Definition at line 4653 of file rsaenh.c.

4654{
4656}
HRESULT __wine_register_resources(HMODULE module) DECLSPEC_HIDDEN
Definition: register.c:98

◆ DllUnregisterServer()

HRESULT WINAPI DllUnregisterServer ( void  )

Definition at line 4661 of file rsaenh.c.

4662{
4664}
HRESULT __wine_unregister_resources(HMODULE module) DECLSPEC_HIDDEN
Definition: register.c:110

◆ finalize_hash()

static void finalize_hash ( CRYPTHASH pCryptHash)
inlinestatic

Definition at line 706 of file rsaenh.c.

706 {
707 DWORD dwDataLen;
708
709 switch (pCryptHash->aiAlgid)
710 {
711 case CALG_HMAC:
712 if (pCryptHash->pHMACInfo) {
713 BYTE abHashValue[RSAENH_MAX_HASH_SIZE];
714
715 finalize_hash_impl(pCryptHash->pHMACInfo->HashAlgid, &pCryptHash->context,
716 pCryptHash->abHashValue);
717 memcpy(abHashValue, pCryptHash->abHashValue, pCryptHash->dwHashSize);
718 init_hash_impl(pCryptHash->pHMACInfo->HashAlgid, &pCryptHash->context);
719 update_hash_impl(pCryptHash->pHMACInfo->HashAlgid, &pCryptHash->context,
720 pCryptHash->pHMACInfo->pbOuterString,
721 pCryptHash->pHMACInfo->cbOuterString);
722 update_hash_impl(pCryptHash->pHMACInfo->HashAlgid, &pCryptHash->context,
723 abHashValue, pCryptHash->dwHashSize);
724 finalize_hash_impl(pCryptHash->pHMACInfo->HashAlgid, &pCryptHash->context,
725 pCryptHash->abHashValue);
726 }
727 break;
728
729 case CALG_MAC:
730 dwDataLen = 0;
731 RSAENH_CPEncrypt(pCryptHash->hProv, pCryptHash->hKey, 0, TRUE, 0,
732 pCryptHash->abHashValue, &dwDataLen, pCryptHash->dwHashSize);
733 break;
734
735 default:
736 finalize_hash_impl(pCryptHash->aiAlgid, &pCryptHash->context, pCryptHash->abHashValue);
737 }
738}
BOOL WINAPI RSAENH_CPEncrypt(HCRYPTPROV hProv, HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen, DWORD dwBufLen)
Definition: rsaenh.c:2183
#define RSAENH_MAX_HASH_SIZE
Definition: rsaenh.c:56
BOOL finalize_hash_impl(ALG_ID aiAlgid, HASH_CONTEXT *pHashContext, BYTE *pbHashValue)
Definition: implglue.c:131
BOOL update_hash_impl(ALG_ID aiAlgid, HASH_CONTEXT *pHashContext, const BYTE *pbData, DWORD dwDataLen)
Definition: implglue.c:90
BOOL init_hash_impl(ALG_ID aiAlgid, HASH_CONTEXT *pHashContext)
Definition: implglue.c:54
BYTE * pbOuterString
Definition: wincrypt.h:97
DWORD cbOuterString
Definition: wincrypt.h:98
ALG_ID HashAlgid
Definition: wincrypt.h:94
BYTE abHashValue[RSAENH_MAX_HASH_SIZE]
Definition: rsaenh.c:74
DWORD dwHashSize
Definition: rsaenh.c:71
HASH_CONTEXT context
Definition: rsaenh.c:73
ALG_ID aiAlgid
Definition: rsaenh.c:68
HCRYPTPROV hProv
Definition: rsaenh.c:70
HCRYPTKEY hKey
Definition: rsaenh.c:69
#define CALG_MAC
Definition: wincrypt.h:1808
#define CALG_HMAC
Definition: wincrypt.h:1810

Referenced by RSAENH_CPDeriveKey(), RSAENH_CPGetHashParam(), and tls1_p().

◆ free_data_blob()

static void free_data_blob ( PCRYPT_DATA_BLOB  pBlob)
inlinestatic

Definition at line 527 of file rsaenh.c.

527 {
528 HeapFree(GetProcessHeap(), 0, pBlob->pbData);
529}

Referenced by destroy_hash(), destroy_key(), RSAENH_CPCreateHash(), and tls1_prf().

◆ free_hmac_info()

static void free_hmac_info ( PHMAC_INFO  hmac_info)
inlinestatic

Definition at line 550 of file rsaenh.c.

550 {
551 if (!hmac_info) return;
552 HeapFree(GetProcessHeap(), 0, hmac_info->pbInnerString);
553 HeapFree(GetProcessHeap(), 0, hmac_info->pbOuterString);
554 HeapFree(GetProcessHeap(), 0, hmac_info);
555}
BYTE * pbInnerString
Definition: wincrypt.h:95

Referenced by copy_hmac_info(), destroy_hash(), and RSAENH_CPSetHashParam().

◆ get_algid_info()

static const PROV_ENUMALGS_EX * get_algid_info ( HCRYPTPROV  hProv,
ALG_ID  algid 
)
inlinestatic

Definition at line 446 of file rsaenh.c.

446 {
448 KEYCONTAINER *pKeyContainer;
449
450 if (!(pKeyContainer = get_key_container(hProv))) return NULL;
451
452 for (iterator = aProvEnumAlgsEx[pKeyContainer->dwPersonality]; iterator->aiAlgid; iterator++) {
453 if (iterator->aiAlgid == algid) return iterator;
454 }
455
457 return NULL;
458}
static KEYCONTAINER * get_key_container(HCRYPTPROV hProv)
Definition: rsaenh.c:420
static const PROV_ENUMALGS_EX aProvEnumAlgsEx[5][RSAENH_MAX_ENUMALGS+1]
Definition: rsaenh.c:170
static HCRYPTPROV hProv
Definition: rsaenh.c:32
DWORD dwPersonality
Definition: rsaenh.c:131

Referenced by init_hash(), new_key(), RSAENH_CPCreateHash(), and RSAENH_CPHashData().

◆ get_key_container()

static KEYCONTAINER * get_key_container ( HCRYPTPROV  hProv)
inlinestatic

Definition at line 420 of file rsaenh.c.

421{
422 KEYCONTAINER *pKeyContainer;
423
425 (OBJECTHDR**)&pKeyContainer))
426 {
428 return NULL;
429 }
430 return pKeyContainer;
431}
#define RSAENH_MAGIC_CONTAINER
Definition: rsaenh.c:126
#define NTE_BAD_UID
Definition: winerror.h:2869

Referenced by get_algid_info(), import_key(), import_private_key(), new_key(), release_and_install_key(), RSAENH_CPGenKey(), RSAENH_CPGetProvParam(), RSAENH_CPGetUserKey(), RSAENH_CPSetKeyParam(), and RSAENH_CPSetProvParam().

◆ import_key()

static BOOL import_key ( HCRYPTPROV  hProv,
const BYTE pbData,
DWORD  dwDataLen,
HCRYPTKEY  hPubKey,
DWORD  dwFlags,
BOOL  fStoreKey,
HCRYPTKEY phKey 
)
static

Definition at line 3066 of file rsaenh.c.

3068{
3069 KEYCONTAINER *pKeyContainer;
3070 const BLOBHEADER *pBlobHeader = (const BLOBHEADER*)pbData;
3071
3072 if (!(pKeyContainer = get_key_container(hProv)))
3073 return FALSE;
3074
3075 if (dwDataLen < sizeof(BLOBHEADER) ||
3076 pBlobHeader->bVersion != CUR_BLOB_VERSION ||
3077 pBlobHeader->reserved != 0)
3078 {
3079 TRACE("bVersion = %d, reserved = %d\n", pBlobHeader->bVersion,
3080 pBlobHeader->reserved);
3082 return FALSE;
3083 }
3084
3085 /* If this is a verify-only context, the key is not persisted regardless of
3086 * fStoreKey's original value.
3087 */
3088 fStoreKey = fStoreKey && !(dwFlags & CRYPT_VERIFYCONTEXT);
3089 TRACE("blob type: %x\n", pBlobHeader->bType);
3090 switch (pBlobHeader->bType)
3091 {
3092 case PRIVATEKEYBLOB:
3093 return import_private_key(hProv, pbData, dwDataLen, dwFlags,
3094 fStoreKey, phKey);
3095
3096 case PUBLICKEYBLOB:
3097 return import_public_key(hProv, pbData, dwDataLen, dwFlags,
3098 phKey);
3099
3100 case SIMPLEBLOB:
3101 return import_symmetric_key(hProv, pbData, dwDataLen, hPubKey,
3102 dwFlags, phKey);
3103
3104 case PLAINTEXTKEYBLOB:
3105 return import_plaintext_key(hProv, pbData, dwDataLen, dwFlags,
3106 phKey);
3107
3108 default:
3109 SetLastError(NTE_BAD_TYPE); /* FIXME: error code? */
3110 return FALSE;
3111 }
3112}
static BOOL import_plaintext_key(HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags, HCRYPTKEY *phKey)
Definition: rsaenh.c:2988
static BOOL import_private_key(HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags, BOOL fStoreKey, HCRYPTKEY *phKey)
Definition: rsaenh.c:2757
static BOOL import_public_key(HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags, HCRYPTKEY *phKey)
Definition: rsaenh.c:2849
static BOOL import_symmetric_key(HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, HCRYPTKEY hPubKey, DWORD dwFlags, HCRYPTKEY *phKey)
Definition: rsaenh.c:2912
#define TRACE(s)
Definition: solgame.cpp:4
#define NTE_BAD_DATA
Definition: winerror.h:2873

Referenced by read_key_value(), and RSAENH_CPImportKey().

◆ import_plaintext_key()

static BOOL import_plaintext_key ( HCRYPTPROV  hProv,
const BYTE pbData,
DWORD  dwDataLen,
DWORD  dwFlags,
HCRYPTKEY phKey 
)
static

Definition at line 2988 of file rsaenh.c.

2990{
2991 CRYPTKEY *pCryptKey;
2992 const BLOBHEADER *pBlobHeader = (const BLOBHEADER*)pbData;
2993 const DWORD *pKeyLen = (const DWORD *)(pBlobHeader + 1);
2994 const BYTE *pbKeyStream = (const BYTE*)(pKeyLen + 1);
2995
2996 if (dwDataLen < sizeof(BLOBHEADER)+sizeof(DWORD)+*pKeyLen)
2997 {
2998 SetLastError(NTE_BAD_DATA); /* FIXME: error code */
2999 return FALSE;
3000 }
3001
3003 {
3004 *phKey = new_key(hProv, CALG_HMAC, 0, &pCryptKey);
3005 if (*phKey == (HCRYPTKEY)INVALID_HANDLE_VALUE)
3006 return FALSE;
3007 if (*pKeyLen <= RSAENH_MIN(sizeof(pCryptKey->abKeyValue), RSAENH_HMAC_BLOCK_LEN))
3008 {
3009 memcpy(pCryptKey->abKeyValue, pbKeyStream, *pKeyLen);
3010 pCryptKey->dwKeyLen = *pKeyLen;
3011 }
3012 else
3013 {
3014 CRYPT_DATA_BLOB blobHmacKey = { *pKeyLen, (BYTE *)pbKeyStream };
3015
3016 /* In order to initialize an HMAC key, the key material is hashed,
3017 * and the output of the hash function is used as the key material.
3018 * Unfortunately, the way the Crypto API is designed, we don't know
3019 * the hash algorithm yet, so we have to copy the entire key
3020 * material.
3021 */
3022 if (!copy_data_blob(&pCryptKey->blobHmacKey, &blobHmacKey))
3023 {
3026 return FALSE;
3027 }
3028 }
3029 setup_key(pCryptKey);
3031 pCryptKey->dwPermissions |= CRYPT_EXPORT;
3032 }
3033 else
3034 {
3035 *phKey = new_key(hProv, pBlobHeader->aiKeyAlg, *pKeyLen<<19, &pCryptKey);
3036 if (*phKey == (HCRYPTKEY)INVALID_HANDLE_VALUE)
3037 return FALSE;
3038 memcpy(pCryptKey->abKeyValue, pbKeyStream, *pKeyLen);
3039 setup_key(pCryptKey);
3041 pCryptKey->dwPermissions |= CRYPT_EXPORT;
3042 }
3043 return TRUE;
3044}
static const WCHAR setup_key[]
Definition: advpack.c:44
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL release_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType)
Definition: handle.c:230
static HCRYPTKEY new_key(HCRYPTPROV hProv, ALG_ID aiAlgid, DWORD dwFlags, CRYPTKEY **ppCryptKey)
Definition: rsaenh.c:794
#define RSAENH_MIN(a, b)
Definition: rsaenh.c:164
static BOOL copy_data_blob(PCRYPT_DATA_BLOB dst, const PCRYPT_DATA_BLOB src)
Definition: rsaenh.c:476
#define RSAENH_HMAC_BLOCK_LEN
Definition: rsaenh.c:148
#define DWORD
Definition: nt_native.h:44
#define CRYPT_IPSEC_HMAC_KEY
Definition: wincrypt.h:91
ULONG_PTR HCRYPTKEY
Definition: wincrypt.h:49
#define CRYPT_EXPORTABLE
Definition: wincrypt.h:2206

Referenced by import_key().

◆ import_private_key()

static BOOL import_private_key ( HCRYPTPROV  hProv,
const BYTE pbData,
DWORD  dwDataLen,
DWORD  dwFlags,
BOOL  fStoreKey,
HCRYPTKEY phKey 
)
static

Definition at line 2757 of file rsaenh.c.

2759{
2760 KEYCONTAINER *pKeyContainer;
2761 CRYPTKEY *pCryptKey;
2762 const BLOBHEADER *pBlobHeader = (const BLOBHEADER*)pbData;
2763 const RSAPUBKEY *pRSAPubKey = (const RSAPUBKEY*)(pBlobHeader+1);
2764 BOOL ret;
2765
2767 {
2768 FIXME("unimplemented for CRYPT_IPSEC_HMAC_KEY\n");
2770 return FALSE;
2771 }
2772 if (!(pKeyContainer = get_key_container(hProv)))
2773 return FALSE;
2774
2775 if ((dwDataLen < sizeof(BLOBHEADER) + sizeof(RSAPUBKEY)))
2776 {
2777 ERR("datalen %d not long enough for a BLOBHEADER + RSAPUBKEY\n",
2778 dwDataLen);
2780 return FALSE;
2781 }
2782 if (pRSAPubKey->magic != RSAENH_MAGIC_RSA2)
2783 {
2784 ERR("unexpected magic %08x\n", pRSAPubKey->magic);
2786 return FALSE;
2787 }
2788 if ((dwDataLen < sizeof(BLOBHEADER) + sizeof(RSAPUBKEY) +
2789 (pRSAPubKey->bitlen >> 3) + (5 * ((pRSAPubKey->bitlen+8)>>4))))
2790 {
2791 DWORD expectedLen = sizeof(BLOBHEADER) + sizeof(RSAPUBKEY) +
2792 (pRSAPubKey->bitlen >> 3) + (5 * ((pRSAPubKey->bitlen+8)>>4));
2793
2794 ERR("blob too short for pub key: expect %d, got %d\n",
2795 expectedLen, dwDataLen);
2797 return FALSE;
2798 }
2799
2800 *phKey = new_key(hProv, pBlobHeader->aiKeyAlg, MAKELONG(0,pRSAPubKey->bitlen), &pCryptKey);
2801 if (*phKey == (HCRYPTKEY)INVALID_HANDLE_VALUE) return FALSE;
2802 setup_key(pCryptKey);
2803 ret = import_private_key_impl((const BYTE*)(pRSAPubKey+1), &pCryptKey->context,
2804 pRSAPubKey->bitlen/8, dwDataLen, pRSAPubKey->pubexp);
2805 if (ret) {
2807 pCryptKey->dwPermissions |= CRYPT_EXPORT;
2808 switch (pBlobHeader->aiKeyAlg)
2809 {
2810 case AT_SIGNATURE:
2811 case CALG_RSA_SIGN:
2812 TRACE("installing signing key\n");
2813 release_and_install_key(hProv, *phKey, &pKeyContainer->hSignatureKeyPair,
2814 fStoreKey);
2815 break;
2816 case AT_KEYEXCHANGE:
2817 case CALG_RSA_KEYX:
2818 TRACE("installing key exchange key\n");
2819 release_and_install_key(hProv, *phKey, &pKeyContainer->hKeyExchangeKeyPair,
2820 fStoreKey);
2821 break;
2822 }
2823 }
2824 return ret;
2825}
#define FIXME(fmt,...)
Definition: debug.h:111
#define ERR(fmt,...)
Definition: debug.h:110
static void release_and_install_key(HCRYPTPROV hProv, HCRYPTKEY src, HCRYPTKEY *dest, DWORD fStoreKey)
Definition: rsaenh.c:2717
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL import_private_key_impl(const BYTE *pbSrc, KEY_CONTEXT *pKeyContext, DWORD dwKeyLen, DWORD dwDataLen, DWORD dwPubExp)
Definition: implglue.c:487
HCRYPTKEY hSignatureKeyPair
Definition: rsaenh.c:137
HCRYPTKEY hKeyExchangeKeyPair
Definition: rsaenh.c:136
#define MAKELONG(a, b)
Definition: typedefs.h:249
int ret
#define AT_KEYEXCHANGE
Definition: wincrypt.h:2035
#define AT_SIGNATURE
Definition: wincrypt.h:2036
#define NTE_BAD_FLAGS
Definition: winerror.h:2877

Referenced by import_key().

◆ import_public_key()

static BOOL import_public_key ( HCRYPTPROV  hProv,
const BYTE pbData,
DWORD  dwDataLen,
DWORD  dwFlags,
HCRYPTKEY phKey 
)
static

Definition at line 2849 of file rsaenh.c.

2851{
2852 CRYPTKEY *pCryptKey;
2853 const BLOBHEADER *pBlobHeader = (const BLOBHEADER*)pbData;
2854 const RSAPUBKEY *pRSAPubKey = (const RSAPUBKEY*)(pBlobHeader+1);
2855 ALG_ID algID;
2856 BOOL ret;
2857
2859 {
2860 FIXME("unimplemented for CRYPT_IPSEC_HMAC_KEY\n");
2862 return FALSE;
2863 }
2864
2865 if ((dwDataLen < sizeof(BLOBHEADER) + sizeof(RSAPUBKEY)) ||
2866 (pRSAPubKey->magic != RSAENH_MAGIC_RSA1) ||
2867 (dwDataLen < sizeof(BLOBHEADER) + sizeof(RSAPUBKEY) + (pRSAPubKey->bitlen >> 3)))
2868 {
2870 return FALSE;
2871 }
2872
2873 /* Since this is a public key blob, only the public key is
2874 * available, so only signature verification is possible.
2875 */
2876 algID = pBlobHeader->aiKeyAlg;
2877 *phKey = new_key(hProv, algID, MAKELONG(0,pRSAPubKey->bitlen), &pCryptKey);
2878 if (*phKey == (HCRYPTKEY)INVALID_HANDLE_VALUE) return FALSE;
2879 setup_key(pCryptKey);
2880 ret = import_public_key_impl((const BYTE*)(pRSAPubKey+1), &pCryptKey->context,
2881 pRSAPubKey->bitlen >> 3, pRSAPubKey->pubexp);
2882 if (ret) {
2884 pCryptKey->dwPermissions |= CRYPT_EXPORT;
2885 }
2886 return ret;
2887}
BOOL import_public_key_impl(const BYTE *pbSrc, KEY_CONTEXT *pKeyContext, DWORD dwKeyLen, DWORD dwPubExp)
Definition: implglue.c:412

Referenced by import_key().

◆ import_symmetric_key()

static BOOL import_symmetric_key ( HCRYPTPROV  hProv,
const BYTE pbData,
DWORD  dwDataLen,
HCRYPTKEY  hPubKey,
DWORD  dwFlags,
HCRYPTKEY phKey 
)
static

Definition at line 2912 of file rsaenh.c.

2914{
2915 CRYPTKEY *pCryptKey, *pPubKey;
2916 const BLOBHEADER *pBlobHeader = (const BLOBHEADER*)pbData;
2917 const ALG_ID *pAlgid = (const ALG_ID*)(pBlobHeader+1);
2918 const BYTE *pbKeyStream = (const BYTE*)(pAlgid + 1);
2919 BYTE *pbDecrypted;
2920 DWORD dwKeyLen;
2921
2923 {
2924 FIXME("unimplemented for CRYPT_IPSEC_HMAC_KEY\n");
2926 return FALSE;
2927 }
2928 if (!lookup_handle(&handle_table, hPubKey, RSAENH_MAGIC_KEY, (OBJECTHDR**)&pPubKey) ||
2929 pPubKey->aiAlgid != CALG_RSA_KEYX)
2930 {
2931 SetLastError(NTE_BAD_PUBLIC_KEY); /* FIXME: error code? */
2932 return FALSE;
2933 }
2934
2935 if (dwDataLen < sizeof(BLOBHEADER)+sizeof(ALG_ID)+pPubKey->dwBlockLen)
2936 {
2937 SetLastError(NTE_BAD_DATA); /* FIXME: error code */
2938 return FALSE;
2939 }
2940
2941 pbDecrypted = HeapAlloc(GetProcessHeap(), 0, pPubKey->dwBlockLen);
2942 if (!pbDecrypted) return FALSE;
2943 encrypt_block_impl(pPubKey->aiAlgid, PK_PRIVATE, &pPubKey->context, pbKeyStream, pbDecrypted,
2945
2946 dwKeyLen = RSAENH_MAX_KEY_SIZE;
2947 if (!unpad_data(pbDecrypted, pPubKey->dwBlockLen, pbDecrypted, &dwKeyLen, dwFlags)) {
2948 HeapFree(GetProcessHeap(), 0, pbDecrypted);
2949 return FALSE;
2950 }
2951
2952 *phKey = new_key(hProv, pBlobHeader->aiKeyAlg, dwKeyLen<<19, &pCryptKey);
2953 if (*phKey == (HCRYPTKEY)INVALID_HANDLE_VALUE)
2954 {
2955 HeapFree(GetProcessHeap(), 0, pbDecrypted);
2956 return FALSE;
2957 }
2958 memcpy(pCryptKey->abKeyValue, pbDecrypted, dwKeyLen);
2959 HeapFree(GetProcessHeap(), 0, pbDecrypted);
2960 setup_key(pCryptKey);
2962 pCryptKey->dwPermissions |= CRYPT_EXPORT;
2963 return TRUE;
2964}
static BOOL unpad_data(const BYTE *abData, DWORD dwDataLen, BYTE *abBuffer, DWORD *dwBufferLen, DWORD dwFlags)
Definition: rsaenh.c:1734
#define RSAENH_MAX_KEY_SIZE
Definition: rsaenh.c:83
#define RSAENH_DECRYPT
Definition: rsaenh.c:144
#define PK_PRIVATE
Definition: tomcrypt.h:449

Referenced by import_key().

◆ init_data_blob()

static void init_data_blob ( PCRYPT_DATA_BLOB  pBlob)
inlinestatic

Definition at line 534 of file rsaenh.c.

534 {
535 pBlob->pbData = NULL;
536 pBlob->cbData = 0;
537}

Referenced by new_key(), and RSAENH_CPCreateHash().

◆ init_hash()

static BOOL init_hash ( CRYPTHASH pCryptHash)
inlinestatic

Definition at line 630 of file rsaenh.c.

630 {
631 DWORD dwLen;
632
633 switch (pCryptHash->aiAlgid)
634 {
635 case CALG_HMAC:
636 if (pCryptHash->pHMACInfo) {
637 const PROV_ENUMALGS_EX *pAlgInfo;
638
639 pAlgInfo = get_algid_info(pCryptHash->hProv, pCryptHash->pHMACInfo->HashAlgid);
640 if (!pAlgInfo) return FALSE;
641 pCryptHash->dwHashSize = pAlgInfo->dwDefaultLen >> 3;
642 init_hash_impl(pCryptHash->pHMACInfo->HashAlgid, &pCryptHash->context);
643 update_hash_impl(pCryptHash->pHMACInfo->HashAlgid, &pCryptHash->context,
644 pCryptHash->pHMACInfo->pbInnerString,
645 pCryptHash->pHMACInfo->cbInnerString);
646 }
647 return TRUE;
648
649 case CALG_MAC:
650 dwLen = sizeof(DWORD);
651 RSAENH_CPGetKeyParam(pCryptHash->hProv, pCryptHash->hKey, KP_BLOCKLEN,
652 (BYTE*)&pCryptHash->dwHashSize, &dwLen, 0);
653 pCryptHash->dwHashSize >>= 3;
654 return TRUE;
655
656 default:
657 return init_hash_impl(pCryptHash->aiAlgid, &pCryptHash->context);
658 }
659}
static const PROV_ENUMALGS_EX * get_algid_info(HCRYPTPROV hProv, ALG_ID algid)
Definition: rsaenh.c:446
BOOL WINAPI RSAENH_CPGetKeyParam(HCRYPTPROV hProv, HCRYPTKEY hKey, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
Definition: rsaenh.c:3601
DWORD cbInnerString
Definition: wincrypt.h:96
DWORD dwDefaultLen
Definition: wincrypt.h:69
#define KP_BLOCKLEN
Definition: wincrypt.h:2135

Referenced by RSAENH_CPCreateHash(), RSAENH_CPDeriveKey(), RSAENH_CPSetHashParam(), and tls1_p().

◆ map_key_spec_to_key_pair_name()

static LPCSTR map_key_spec_to_key_pair_name ( DWORD  dwKeySpec)
static

Definition at line 969 of file rsaenh.c.

970{
971 LPCSTR szValueName;
972
973 switch (dwKeySpec)
974 {
975 case AT_KEYEXCHANGE:
976 szValueName = "KeyExchangeKeyPair";
977 break;
978 case AT_SIGNATURE:
979 szValueName = "SignatureKeyPair";
980 break;
981 default:
982 WARN("invalid key spec %d\n", dwKeySpec);
983 szValueName = NULL;
984 }
985 return szValueName;
986}
#define WARN(fmt,...)
Definition: debug.h:112
const char * LPCSTR
Definition: xmlstorage.h:183

Referenced by read_key_value(), and store_key_pair().

◆ map_key_spec_to_permissions_name()

static LPCSTR map_key_spec_to_permissions_name ( DWORD  dwKeySpec)
static

Definition at line 1050 of file rsaenh.c.

1051{
1052 LPCSTR szValueName;
1053
1054 switch (dwKeySpec)
1055 {
1056 case AT_KEYEXCHANGE:
1057 szValueName = "KeyExchangePermissions";
1058 break;
1059 case AT_SIGNATURE:
1060 szValueName = "SignaturePermissions";
1061 break;
1062 default:
1063 WARN("invalid key spec %d\n", dwKeySpec);
1064 szValueName = NULL;
1065 }
1066 return szValueName;
1067}

Referenced by read_key_value(), and store_key_permissions().

◆ new_key()

static HCRYPTKEY new_key ( HCRYPTPROV  hProv,
ALG_ID  aiAlgid,
DWORD  dwFlags,
CRYPTKEY **  ppCryptKey 
)
static

Definition at line 794 of file rsaenh.c.

795{
796 HCRYPTKEY hCryptKey;
797 CRYPTKEY *pCryptKey;
798 DWORD dwKeyLen = HIWORD(dwFlags), bKeyLen = dwKeyLen;
799 const PROV_ENUMALGS_EX *peaAlgidInfo;
800
801 *ppCryptKey = NULL;
802
803 /*
804 * Retrieve the CSP's capabilities for the given ALG_ID value
805 */
806 peaAlgidInfo = get_algid_info(hProv, aiAlgid);
807 if (!peaAlgidInfo) return (HCRYPTKEY)INVALID_HANDLE_VALUE;
808
809 TRACE("alg = %s, dwKeyLen = %d\n", debugstr_a(peaAlgidInfo->szName),
810 dwKeyLen);
811 /*
812 * Assume the default key length, if none is specified explicitly
813 */
814 if (dwKeyLen == 0) dwKeyLen = peaAlgidInfo->dwDefaultLen;
815
816 /*
817 * Check if the requested key length is supported by the current CSP.
818 * Adjust key length's for DES algorithms.
819 */
820 switch (aiAlgid) {
821 case CALG_DES:
822 if (dwKeyLen == RSAENH_DES_EFFECTIVE_KEYLEN) {
823 dwKeyLen = RSAENH_DES_STORAGE_KEYLEN;
824 }
825 if (dwKeyLen != RSAENH_DES_STORAGE_KEYLEN) {
828 }
829 break;
830
831 case CALG_3DES_112:
832 if (dwKeyLen == RSAENH_3DES112_EFFECTIVE_KEYLEN) {
834 }
835 if (dwKeyLen != RSAENH_3DES112_STORAGE_KEYLEN) {
838 }
839 break;
840
841 case CALG_3DES:
842 if (dwKeyLen == RSAENH_3DES_EFFECTIVE_KEYLEN) {
844 }
845 if (dwKeyLen != RSAENH_3DES_STORAGE_KEYLEN) {
848 }
849 break;
850
851 case CALG_HMAC:
852 /* Avoid the key length check for HMAC keys, which have unlimited
853 * length.
854 */
855 break;
856
857 case CALG_AES:
858 if (!bKeyLen)
859 {
860 TRACE("missing key len for CALG_AES\n");
863 }
864 /* fall through */
865 default:
866 if (dwKeyLen % 8 ||
867 dwKeyLen > peaAlgidInfo->dwMaxLen ||
868 dwKeyLen < peaAlgidInfo->dwMinLen)
869 {
870 TRACE("key len %d out of bounds (%d, %d)\n", dwKeyLen,
871 peaAlgidInfo->dwMinLen, peaAlgidInfo->dwMaxLen);
874 }
875 }
876
877 hCryptKey = new_object(&handle_table, sizeof(CRYPTKEY), RSAENH_MAGIC_KEY,
878 destroy_key, (OBJECTHDR**)&pCryptKey);
879 if (hCryptKey != (HCRYPTKEY)INVALID_HANDLE_VALUE)
880 {
881 KEYCONTAINER *pKeyContainer = get_key_container(hProv);
882 pCryptKey->aiAlgid = aiAlgid;
883 pCryptKey->hProv = hProv;
884 pCryptKey->dwModeBits = 0;
886 CRYPT_MAC;
888 pCryptKey->dwPermissions |= CRYPT_EXPORT;
889 pCryptKey->dwKeyLen = dwKeyLen >> 3;
890 pCryptKey->dwEffectiveKeyLen = 0;
891
892 /*
893 * For compatibility reasons a 40 bit key on the Enhanced
894 * provider will not have salt
895 */
896 if (pKeyContainer->dwPersonality == RSAENH_PERSONALITY_ENHANCED
897 && (aiAlgid == CALG_RC2 || aiAlgid == CALG_RC4)
898 && (dwFlags & CRYPT_CREATE_SALT) && dwKeyLen == 40)
899 pCryptKey->dwSaltLen = 0;
900 else if ((dwFlags & CRYPT_CREATE_SALT) || (dwKeyLen == 40 && !(dwFlags & CRYPT_NO_SALT)))
901 pCryptKey->dwSaltLen = 16 /*FIXME*/ - pCryptKey->dwKeyLen;
902 else
903 pCryptKey->dwSaltLen = 0;
904 memset(pCryptKey->abKeyValue, 0, sizeof(pCryptKey->abKeyValue));
905 memset(pCryptKey->abInitVector, 0, sizeof(pCryptKey->abInitVector));
906 memset(&pCryptKey->siSChannelInfo.saEncAlg, 0, sizeof(pCryptKey->siSChannelInfo.saEncAlg));
907 memset(&pCryptKey->siSChannelInfo.saMACAlg, 0, sizeof(pCryptKey->siSChannelInfo.saMACAlg));
910 init_data_blob(&pCryptKey->blobHmacKey);
911
912 switch(aiAlgid)
913 {
914 case CALG_PCT1_MASTER:
915 case CALG_SSL2_MASTER:
916 case CALG_SSL3_MASTER:
917 case CALG_TLS1_MASTER:
918 case CALG_RC4:
919 pCryptKey->dwBlockLen = 0;
920 pCryptKey->dwMode = 0;
921 break;
922
923 case CALG_RC2:
924 case CALG_DES:
925 case CALG_3DES_112:
926 case CALG_3DES:
927 pCryptKey->dwBlockLen = 8;
928 pCryptKey->dwMode = CRYPT_MODE_CBC;
929 break;
930
931 case CALG_AES:
932 case CALG_AES_128:
933 case CALG_AES_192:
934 case CALG_AES_256:
935 pCryptKey->dwBlockLen = 16;
936 pCryptKey->dwMode = CRYPT_MODE_CBC;
937 break;
938
939 case CALG_RSA_KEYX:
940 case CALG_RSA_SIGN:
941 pCryptKey->dwBlockLen = dwKeyLen >> 3;
942 pCryptKey->dwMode = 0;
943 break;
944
945 case CALG_HMAC:
946 pCryptKey->dwBlockLen = 0;
947 pCryptKey->dwMode = 0;
948 break;
949 }
950
951 *ppCryptKey = pCryptKey;
952 }
953
954 return hCryptKey;
955}
HCRYPTKEY new_object(struct handle_table *lpTable, size_t cbSize, DWORD dwType, DESTRUCTOR destructor, OBJECTHDR **ppObject)
Definition: handle.c:353
#define RSAENH_3DES112_EFFECTIVE_KEYLEN
Definition: rsaenh.c:151
#define RSAENH_DES_STORAGE_KEYLEN
Definition: rsaenh.c:150
#define RSAENH_3DES112_STORAGE_KEYLEN
Definition: rsaenh.c:152
static void destroy_key(OBJECTHDR *pObject)
Definition: rsaenh.c:749
#define RSAENH_DES_EFFECTIVE_KEYLEN
Definition: rsaenh.c:149
#define RSAENH_3DES_STORAGE_KEYLEN
Definition: rsaenh.c:154
#define RSAENH_3DES_EFFECTIVE_KEYLEN
Definition: rsaenh.c:153
static void init_data_blob(PCRYPT_DATA_BLOB pBlob)
Definition: rsaenh.c:534
#define RSAENH_PERSONALITY_ENHANCED
Definition: rsaenh.c:122
#define debugstr_a
Definition: kernel32.h:31
CHAR szName[20]
Definition: wincrypt.h:74
SCHANNEL_ALG saMACAlg
Definition: rsaenh.c:91
SCHANNEL_ALG saEncAlg
Definition: rsaenh.c:90
DWORD dwMode
Definition: rsaenh.c:101
DWORD dwEffectiveKeyLen
Definition: rsaenh.c:105
BYTE abInitVector[RSAENH_MAX_BLOCK_SIZE]
Definition: rsaenh.c:111
DWORD dwSaltLen
Definition: rsaenh.c:106
DWORD dwModeBits
Definition: rsaenh.c:102
HCRYPTPROV hProv
Definition: rsaenh.c:100
#define HIWORD(l)
Definition: typedefs.h:247
#define CALG_PCT1_MASTER
Definition: wincrypt.h:1847
#define CALG_RC2
Definition: wincrypt.h:1829
#define CALG_AES_128
Definition: wincrypt.h:1833
#define CRYPT_DECRYPT
Definition: wincrypt.h:2196
#define CALG_AES_192
Definition: wincrypt.h:1834
#define CRYPT_MODE_CBC
Definition: wincrypt.h:2190
#define CALG_RC4
Definition: wincrypt.h:1837
#define CALG_3DES_112
Definition: wincrypt.h:1831
#define CALG_AES
Definition: wincrypt.h:1836
#define CRYPT_CREATE_SALT
Definition: wincrypt.h:2208
#define CRYPT_ENCRYPT
Definition: wincrypt.h:2195
#define CALG_SSL3_MASTER
Definition: wincrypt.h:1843
#define CALG_AES_256
Definition: wincrypt.h:1835
#define CALG_3DES
Definition: wincrypt.h:1830
#define CRYPT_WRITE
Definition: wincrypt.h:2199
#define CRYPT_READ
Definition: wincrypt.h:2198
#define CALG_DES
Definition: wincrypt.h:1828
#define CRYPT_MAC
Definition: wincrypt.h:2200
#define CALG_TLS1_MASTER
Definition: wincrypt.h:1849
#define CRYPT_NO_SALT
Definition: wincrypt.h:2210

Referenced by ___w64_mingwthr_add_key_dtor(), add_key_(), import_plaintext_key(), import_private_key(), import_public_key(), import_symmetric_key(), RSAENH_CPDeriveKey(), RSAENH_CPGenKey(), and tls1_prf().

◆ new_key_container()

static HCRYPTPROV new_key_container ( PCCH  pszContainerName,
DWORD  dwFlags,
const VTableProvStruc pVTable 
)
static

Definition at line 1292 of file rsaenh.c.

1293{
1294 KEYCONTAINER *pKeyContainer;
1295 HCRYPTPROV hKeyContainer;
1296
1298 destroy_key_container, (OBJECTHDR**)&pKeyContainer);
1299 if (hKeyContainer != (HCRYPTPROV)INVALID_HANDLE_VALUE)
1300 {
1301 lstrcpynA(pKeyContainer->szName, pszContainerName, MAX_PATH);
1302 pKeyContainer->dwFlags = dwFlags;
1303 pKeyContainer->dwEnumAlgsCtr = 0;
1306 if (pVTable && pVTable->pszProvName) {
1307 lstrcpynA(pKeyContainer->szProvName, pVTable->pszProvName, MAX_PATH);
1308 if (!strcmp(pVTable->pszProvName, MS_DEF_PROV_A)) {
1309 pKeyContainer->dwPersonality = RSAENH_PERSONALITY_BASE;
1310 } else if (!strcmp(pVTable->pszProvName, MS_ENHANCED_PROV_A)) {
1312 } else if (!strcmp(pVTable->pszProvName, MS_DEF_RSA_SCHANNEL_PROV_A)) {
1314 } else if (!strcmp(pVTable->pszProvName, MS_ENH_RSA_AES_PROV_A) ||
1316 pKeyContainer->dwPersonality = RSAENH_PERSONALITY_AES;
1317 } else {
1319 }
1320 }
1321
1322 /* The new key container has to be inserted into the CSP immediately
1323 * after creation to be available for CPGetProvParam's PP_ENUMCONTAINERS. */
1324 if (!(dwFlags & CRYPT_VERIFYCONTEXT)) {
1325 HKEY hKey;
1326
1327 if (create_container_key(pKeyContainer, KEY_WRITE, &hKey))
1329 }
1330 }
1331
1332 return hKeyContainer;
1333}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define RegCloseKey(hKey)
Definition: registry.h:49
#define lstrcpynA
Definition: compat.h:751
#define RSAENH_PERSONALITY_SCHANNEL
Definition: rsaenh.c:123
#define RSAENH_PERSONALITY_STRONG
Definition: rsaenh.c:121
static BOOL create_container_key(KEYCONTAINER *pKeyContainer, REGSAM sam, HKEY *phKey)
Definition: rsaenh.c:1103
#define RSAENH_PERSONALITY_AES
Definition: rsaenh.c:124
#define RSAENH_PERSONALITY_BASE
Definition: rsaenh.c:120
static void destroy_key_container(OBJECTHDR *pObjectHdr)
Definition: rsaenh.c:1263
FxAutoRegKey hKey
#define KEY_WRITE
Definition: nt_native.h:1031
LPSTR pszProvName
Definition: wincrypt.h:708
DWORD dwEnumAlgsCtr
Definition: rsaenh.c:132
CHAR szProvName[MAX_PATH]
Definition: rsaenh.c:135
#define MS_DEF_PROV_A
Definition: wincrypt.h:1860
#define MS_ENH_RSA_AES_PROV_XP_A
Definition: wincrypt.h:2018
ULONG_PTR HCRYPTPROV
Definition: wincrypt.h:46
#define MS_DEF_RSA_SCHANNEL_PROV_A
Definition: wincrypt.h:1916
#define MS_ENHANCED_PROV_A
Definition: wincrypt.h:1874
#define MS_ENH_RSA_AES_PROV_A
Definition: wincrypt.h:2004

Referenced by read_key_container(), and RSAENH_CPAcquireContext().

◆ open_container_key()

static BOOL open_container_key ( LPCSTR  pszContainerName,
DWORD  dwFlags,
REGSAM  access,
HKEY phKey 
)
static

Definition at line 1134 of file rsaenh.c.

1135{
1136 CHAR szRSABase[MAX_PATH];
1137 HKEY hRootKey;
1138
1139 sprintf(szRSABase, RSAENH_REGKEY, pszContainerName);
1140
1142 hRootKey = HKEY_LOCAL_MACHINE;
1143 else
1144 hRootKey = HKEY_CURRENT_USER;
1145
1146 /* @@ Wine registry key: HKLM\Software\Wine\Crypto\RSA */
1147 /* @@ Wine registry key: HKCU\Software\Wine\Crypto\RSA */
1148 return RegOpenKeyExA(hRootKey, szRSABase, 0, access, phKey) ==
1150}
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3298
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
#define sprintf(buf, format,...)
Definition: sprintf.c:55

Referenced by read_key_container(), RSAENH_CPGetProvParam(), and RSAENH_CPSetProvParam().

◆ pad_data()

static BOOL pad_data ( const BYTE abData,
DWORD  dwDataLen,
BYTE abBuffer,
DWORD  dwBufferLen,
DWORD  dwFlags 
)
static

Definition at line 1693 of file rsaenh.c.

1695{
1696 DWORD i;
1697
1698 /* Ensure there is enough space for PKCS1 #2 padding */
1699 if (dwDataLen > dwBufferLen-11) {
1701 return FALSE;
1702 }
1703
1704 memmove(abBuffer + dwBufferLen - dwDataLen, abData, dwDataLen);
1705
1706 abBuffer[0] = 0x00;
1707 abBuffer[1] = RSAENH_PKC_BLOCKTYPE;
1708 for (i=2; i < dwBufferLen - dwDataLen - 1; i++)
1709 do gen_rand_impl(&abBuffer[i], 1); while (!abBuffer[i]);
1711 for (i-=8; i < dwBufferLen - dwDataLen - 1; i++)
1712 abBuffer[i] = 0x03;
1713 abBuffer[i] = 0x00;
1714
1715 return TRUE;
1716}
#define RSAENH_PKC_BLOCKTYPE
Definition: rsaenh.c:157
BOOL gen_rand_impl(BYTE *pbBuffer, DWORD dwLen)
Definition: implglue.c:396
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
#define NTE_BAD_LEN
Definition: winerror.h:2872

Referenced by crypt_export_simple(), and RSAENH_CPEncrypt().

◆ read_key_container()

static HCRYPTPROV read_key_container ( PCHAR  pszContainerName,
DWORD  dwFlags,
const VTableProvStruc pVTable 
)
static

Definition at line 1412 of file rsaenh.c.

1413{
1414 HKEY hKey;
1415 KEYCONTAINER *pKeyContainer;
1416 HCRYPTPROV hKeyContainer;
1417 HCRYPTKEY hCryptKey;
1418
1419 if (!open_container_key(pszContainerName, dwFlags, KEY_READ, &hKey))
1420 {
1423 }
1424
1425 hKeyContainer = new_key_container(pszContainerName, dwFlags, pVTable);
1426 if (hKeyContainer != (HCRYPTPROV)INVALID_HANDLE_VALUE)
1427 {
1428 DWORD dwProtectFlags = (dwFlags & CRYPT_MACHINE_KEYSET) ?
1430
1431 if (!lookup_handle(&handle_table, hKeyContainer, RSAENH_MAGIC_CONTAINER,
1432 (OBJECTHDR**)&pKeyContainer))
1434
1435 /* read_key_value calls import_key, which calls import_private_key,
1436 * which implicitly installs the key value into the appropriate key
1437 * container key. Thus the ref count is incremented twice, once for
1438 * the output key value, and once for the implicit install, and needs
1439 * to be decremented to balance the two.
1440 */
1441 if (read_key_value(hKeyContainer, hKey, AT_KEYEXCHANGE,
1442 dwProtectFlags, &hCryptKey))
1444 if (read_key_value(hKeyContainer, hKey, AT_SIGNATURE,
1445 dwProtectFlags, &hCryptKey))
1447 }
1448
1449 return hKeyContainer;
1450}
static BOOL open_container_key(LPCSTR pszContainerName, DWORD dwFlags, REGSAM access, HKEY *phKey)
Definition: rsaenh.c:1134
static HCRYPTPROV new_key_container(PCCH pszContainerName, DWORD dwFlags, const VTableProvStruc *pVTable)
Definition: rsaenh.c:1292
static BOOL read_key_value(HCRYPTPROV hKeyContainer, HKEY hKey, DWORD dwKeySpec, DWORD dwFlags, HCRYPTKEY *phCryptKey)
Definition: rsaenh.c:1347
#define KEY_READ
Definition: nt_native.h:1023
#define CRYPTPROTECT_LOCAL_MACHINE
Definition: wincrypt.h:2228

Referenced by RSAENH_CPAcquireContext().

◆ read_key_value()

static BOOL read_key_value ( HCRYPTPROV  hKeyContainer,
HKEY  hKey,
DWORD  dwKeySpec,
DWORD  dwFlags,
HCRYPTKEY phCryptKey 
)
static

Definition at line 1347 of file rsaenh.c.

1348{
1349 LPCSTR szValueName;
1350 DWORD dwValueType, dwLen;
1351 BYTE *pbKey;
1352 DATA_BLOB blobIn, blobOut;
1353 BOOL ret = FALSE;
1354
1355 if (!(szValueName = map_key_spec_to_key_pair_name(dwKeySpec)))
1356 return FALSE;
1357 if (RegQueryValueExA(hKey, szValueName, 0, &dwValueType, NULL, &dwLen) ==
1359 {
1360 pbKey = HeapAlloc(GetProcessHeap(), 0, dwLen);
1361 if (pbKey)
1362 {
1363 if (RegQueryValueExA(hKey, szValueName, 0, &dwValueType, pbKey, &dwLen) ==
1365 {
1366 blobIn.pbData = pbKey;
1367 blobIn.cbData = dwLen;
1368
1369 if (CryptUnprotectData(&blobIn, NULL, NULL, NULL, NULL,
1370 dwFlags, &blobOut))
1371 {
1372 ret = import_key(hKeyContainer, blobOut.pbData, blobOut.cbData, 0, 0,
1373 FALSE, phCryptKey);
1374 LocalFree(blobOut.pbData);
1375 }
1376 }
1377 HeapFree(GetProcessHeap(), 0, pbKey);
1378 }
1379 }
1380 if (ret)
1381 {
1382 CRYPTKEY *pKey;
1383
1384 if (lookup_handle(&handle_table, *phCryptKey, RSAENH_MAGIC_KEY,
1385 (OBJECTHDR**)&pKey))
1386 {
1387 if ((szValueName = map_key_spec_to_permissions_name(dwKeySpec)))
1388 {
1389 dwLen = sizeof(pKey->dwPermissions);
1390 RegQueryValueExA(hKey, szValueName, 0, NULL,
1391 (BYTE *)&pKey->dwPermissions, &dwLen);
1392 }
1393 }
1394 }
1395 return ret;
1396}
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4009
BOOL WINAPI CryptUnprotectData(DATA_BLOB *pDataIn, LPWSTR *ppszDataDescr, DATA_BLOB *pOptionalEntropy, PVOID pvReserved, CRYPTPROTECT_PROMPTSTRUCT *pPromptStruct, DWORD dwFlags, DATA_BLOB *pDataOut)
Definition: protectdata.c:990
static LPCSTR map_key_spec_to_key_pair_name(DWORD dwKeySpec)
Definition: rsaenh.c:969
static BOOL import_key(HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, HCRYPTKEY hPubKey, DWORD dwFlags, BOOL fStoreKey, HCRYPTKEY *phKey)
Definition: rsaenh.c:3066
static LPCSTR map_key_spec_to_permissions_name(DWORD dwKeySpec)
Definition: rsaenh.c:1050
FxRegKey * pKey
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594

Referenced by read_key_container().

◆ release_and_install_key()

static void release_and_install_key ( HCRYPTPROV  hProv,
HCRYPTKEY  src,
HCRYPTKEY dest,
DWORD  fStoreKey 
)
static

Definition at line 2717 of file rsaenh.c.

2719{
2722 if (fStoreKey)
2723 {
2724 KEYCONTAINER *pKeyContainer;
2725
2726 if ((pKeyContainer = get_key_container(hProv)))
2727 {
2728 store_key_container_keys(pKeyContainer);
2729 store_key_container_permissions(pKeyContainer);
2730 }
2731 }
2732}
BOOL copy_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType, HCRYPTKEY *copy)
Definition: handle.c:310
BOOL WINAPI RSAENH_CPDestroyKey(HCRYPTPROV hProv, HCRYPTKEY hKey)
Definition: rsaenh.c:2023
static char * dest
Definition: rtl.c:135

Referenced by import_private_key(), and RSAENH_CPGenKey().

◆ release_key_container_keys()

static void release_key_container_keys ( KEYCONTAINER pKeyContainer)
static

Definition at line 1247 of file rsaenh.c.

1248{
1253}

Referenced by destroy_key_container().

◆ RSAENH_CPAcquireContext()

BOOL WINAPI RSAENH_CPAcquireContext ( HCRYPTPROV phProv,
LPSTR  pszContainer,
DWORD  dwFlags,
PVTableProvStruc  pVTable 
)

Definition at line 1785 of file rsaenh.c.

1787{
1788 CHAR szKeyContainerName[MAX_PATH];
1789
1790 TRACE("(phProv=%p, pszContainer=%s, dwFlags=%08x, pVTable=%p)\n", phProv,
1791 debugstr_a(pszContainer), dwFlags, pVTable);
1792
1793 if (pszContainer && *pszContainer)
1794 {
1795 lstrcpynA(szKeyContainerName, pszContainer, MAX_PATH);
1796 }
1797 else
1798 {
1799 DWORD dwLen = sizeof(szKeyContainerName);
1800 if (!GetUserNameA(szKeyContainerName, &dwLen)) return FALSE;
1801 }
1802
1804 {
1805 case 0:
1806 *phProv = read_key_container(szKeyContainerName, dwFlags, pVTable);
1807 break;
1808
1809 case CRYPT_DELETEKEYSET:
1810 return delete_container_key(szKeyContainerName, dwFlags);
1811
1812 case CRYPT_NEWKEYSET:
1813 *phProv = read_key_container(szKeyContainerName, dwFlags, pVTable);
1814 if (*phProv != (HCRYPTPROV)INVALID_HANDLE_VALUE)
1815 {
1817 TRACE("Can't create new keyset, already exists\n");
1819 return FALSE;
1820 }
1821 *phProv = new_key_container(szKeyContainerName, dwFlags, pVTable);
1822 break;
1823
1826 if (pszContainer && *pszContainer) {
1827 TRACE("pszContainer should be empty\n");
1829 return FALSE;
1830 }
1831 *phProv = new_key_container("", dwFlags, pVTable);
1832 break;
1833
1834 default:
1837 return FALSE;
1838 }
1839
1840 if (*phProv != (HCRYPTPROV)INVALID_HANDLE_VALUE) {
1842 return TRUE;
1843 } else {
1844 return FALSE;
1845 }
1846}
BOOL WINAPI GetUserNameA(LPSTR lpszName, LPDWORD lpSize)
Definition: misc.c:246
static BOOL delete_container_key(LPCSTR pszContainerName, DWORD dwFlags)
Definition: rsaenh.c:1161
static HCRYPTPROV read_key_container(PCHAR pszContainerName, DWORD dwFlags, const VTableProvStruc *pVTable)
Definition: rsaenh.c:1412
#define CRYPT_NEWKEYSET
Definition: wincrypt.h:2070
#define CRYPT_DELETEKEYSET
Definition: wincrypt.h:2071
#define NTE_EXISTS
Definition: winerror.h:2883

◆ RSAENH_CPCreateHash()

BOOL WINAPI RSAENH_CPCreateHash ( HCRYPTPROV  hProv,
ALG_ID  Algid,
HCRYPTKEY  hKey,
DWORD  dwFlags,
HCRYPTHASH phHash 
)

Definition at line 1868 of file rsaenh.c.

1870{
1871 CRYPTKEY *pCryptKey;
1872 CRYPTHASH *pCryptHash;
1873 const PROV_ENUMALGS_EX *peaAlgidInfo;
1874
1875 TRACE("(hProv=%08lx, Algid=%08x, hKey=%08lx, dwFlags=%08x, phHash=%p)\n", hProv, Algid, hKey,
1876 dwFlags, phHash);
1877
1878 peaAlgidInfo = get_algid_info(hProv, Algid);
1879 if (!peaAlgidInfo) return FALSE;
1880
1881 if (dwFlags)
1882 {
1884 return FALSE;
1885 }
1886
1887 if (Algid == CALG_MAC || Algid == CALG_HMAC || Algid == CALG_SCHANNEL_MASTER_HASH ||
1888 Algid == CALG_TLS1PRF)
1889 {
1890 if (!lookup_handle(&handle_table, hKey, RSAENH_MAGIC_KEY, (OBJECTHDR**)&pCryptKey)) {
1892 return FALSE;
1893 }
1894
1895 if ((Algid == CALG_MAC) && (GET_ALG_TYPE(pCryptKey->aiAlgid) != ALG_TYPE_BLOCK)) {
1897 return FALSE;
1898 }
1899
1900 if ((Algid == CALG_SCHANNEL_MASTER_HASH || Algid == CALG_TLS1PRF) &&
1901 (pCryptKey->aiAlgid != CALG_TLS1_MASTER))
1902 {
1904 return FALSE;
1905 }
1906 if (Algid == CALG_SCHANNEL_MASTER_HASH &&
1907 ((!pCryptKey->siSChannelInfo.blobClientRandom.cbData) ||
1908 (!pCryptKey->siSChannelInfo.blobServerRandom.cbData)))
1909 {
1911 return FALSE;
1912 }
1913
1914 if ((Algid == CALG_TLS1PRF) && (pCryptKey->dwState != RSAENH_KEYSTATE_MASTERKEY)) {
1916 return FALSE;
1917 }
1918 }
1919
1921 destroy_hash, (OBJECTHDR**)&pCryptHash);
1922 if (!pCryptHash) return FALSE;
1923
1924 pCryptHash->aiAlgid = Algid;
1925 pCryptHash->hKey = hKey;
1926 pCryptHash->hProv = hProv;
1927 pCryptHash->dwState = RSAENH_HASHSTATE_HASHING;
1928 pCryptHash->pHMACInfo = NULL;
1929 pCryptHash->dwHashSize = peaAlgidInfo->dwDefaultLen >> 3;
1930 init_data_blob(&pCryptHash->tpPRFParams.blobLabel);
1931 init_data_blob(&pCryptHash->tpPRFParams.blobSeed);
1932
1933 if (Algid == CALG_SCHANNEL_MASTER_HASH) {
1934 static const char keyex[] = "key expansion";
1935 BYTE key_expansion[sizeof keyex];
1936 CRYPT_DATA_BLOB blobRandom, blobKeyExpansion = { 13, key_expansion };
1937
1938 memcpy( key_expansion, keyex, sizeof keyex );
1939
1940 if (pCryptKey->dwState != RSAENH_KEYSTATE_MASTERKEY) {
1941 static const char msec[] = "master secret";
1942 BYTE master_secret[sizeof msec];
1943 CRYPT_DATA_BLOB blobLabel = { 13, master_secret };
1944 BYTE abKeyValue[48];
1945
1946 memcpy( master_secret, msec, sizeof msec );
1947
1948 /* See RFC 2246, chapter 8.1 */
1949 if (!concat_data_blobs(&blobRandom,
1950 &pCryptKey->siSChannelInfo.blobClientRandom,
1951 &pCryptKey->siSChannelInfo.blobServerRandom))
1952 {
1953 return FALSE;
1954 }
1955 tls1_prf(hProv, hKey, &blobLabel, &blobRandom, abKeyValue, 48);
1956 pCryptKey->dwState = RSAENH_KEYSTATE_MASTERKEY;
1957 memcpy(pCryptKey->abKeyValue, abKeyValue, 48);
1958 free_data_blob(&blobRandom);
1959 }
1960
1961 /* See RFC 2246, chapter 6.3 */
1962 if (!concat_data_blobs(&blobRandom,
1963 &pCryptKey->siSChannelInfo.blobServerRandom,
1964 &pCryptKey->siSChannelInfo.blobClientRandom))
1965 {
1966 return FALSE;
1967 }
1968 tls1_prf(hProv, hKey, &blobKeyExpansion, &blobRandom, pCryptHash->abHashValue,
1970 free_data_blob(&blobRandom);
1971 }
1972
1973 return init_hash(pCryptHash);
1974}
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define RSAENH_MAGIC_HASH
Definition: rsaenh.c:55
static BOOL concat_data_blobs(PCRYPT_DATA_BLOB dst, const PCRYPT_DATA_BLOB src1, const PCRYPT_DATA_BLOB src2)
Definition: rsaenh.c:505
static BOOL tls1_prf(HCRYPTPROV hProv, HCRYPTPROV hSecret, const PCRYPT_DATA_BLOB pblobLabel, const PCRYPT_DATA_BLOB pblobSeed, BYTE *pbBuffer, DWORD dwBufferLen)
Definition: rsaenh.c:1624
static void destroy_hash(OBJECTHDR *pObject)
Definition: rsaenh.c:612
#define RSAENH_KEYSTATE_MASTERKEY
Definition: rsaenh.c:87
static BOOL init_hash(CRYPTHASH *pCryptHash)
Definition: rsaenh.c:630
#define RSAENH_HASHSTATE_HASHING
Definition: rsaenh.c:57
DWORD dwState
Definition: rsaenh.c:72
#define CALG_SCHANNEL_MASTER_HASH
Definition: wincrypt.h:1844
#define GET_ALG_TYPE(x)
Definition: wincrypt.h:1710
#define CALG_TLS1PRF
Definition: wincrypt.h:1811
#define ALG_TYPE_BLOCK
Definition: wincrypt.h:1725

Referenced by RSAENH_CPSetHashParam(), and tls1_prf().

◆ RSAENH_CPDecrypt()

BOOL WINAPI RSAENH_CPDecrypt ( HCRYPTPROV  hProv,
HCRYPTKEY  hKey,
HCRYPTHASH  hHash,
BOOL  Final,
DWORD  dwFlags,
BYTE pbData,
DWORD pdwDataLen 
)

Definition at line 2335 of file rsaenh.c.

2337{
2338 CRYPTKEY *pCryptKey;
2340 DWORD i, j, k;
2341 DWORD dwMax;
2342
2343 TRACE("(hProv=%08lx, hKey=%08lx, hHash=%08lx, Final=%d, dwFlags=%08x, pbData=%p, "
2344 "pdwDataLen=%p)\n", hProv, hKey, hHash, Final, dwFlags, pbData, pdwDataLen);
2345
2347 {
2349 return FALSE;
2350 }
2351
2352 if (dwFlags)
2353 {
2355 return FALSE;
2356 }
2357
2359 {
2361 return FALSE;
2362 }
2363
2364 if (pCryptKey->dwState == RSAENH_KEYSTATE_IDLE)
2365 pCryptKey->dwState = RSAENH_KEYSTATE_ENCRYPTING;
2366
2367 if (pCryptKey->dwState != RSAENH_KEYSTATE_ENCRYPTING)
2368 {
2370 return FALSE;
2371 }
2372
2373 dwMax=*pdwDataLen;
2374
2375 if (GET_ALG_TYPE(pCryptKey->aiAlgid) == ALG_TYPE_BLOCK) {
2376 for (i=0, in=pbData; i<*pdwDataLen; i+=pCryptKey->dwBlockLen, in+=pCryptKey->dwBlockLen) {
2377 switch (pCryptKey->dwMode) {
2378 case CRYPT_MODE_ECB:
2379 encrypt_block_impl(pCryptKey->aiAlgid, 0, &pCryptKey->context, in, out,
2381 break;
2382
2383 case CRYPT_MODE_CBC:
2384 encrypt_block_impl(pCryptKey->aiAlgid, 0, &pCryptKey->context, in, out,
2386 for (j=0; j<pCryptKey->dwBlockLen; j++) out[j] ^= pCryptKey->abChainVector[j];
2387 memcpy(pCryptKey->abChainVector, in, pCryptKey->dwBlockLen);
2388 break;
2389
2390 case CRYPT_MODE_CFB:
2391 for (j=0; j<pCryptKey->dwBlockLen; j++) {
2392 encrypt_block_impl(pCryptKey->aiAlgid, 0, &pCryptKey->context,
2393 pCryptKey->abChainVector, o, RSAENH_ENCRYPT);
2394 out[j] = in[j] ^ o[0];
2395 for (k=0; k<pCryptKey->dwBlockLen-1; k++)
2396 pCryptKey->abChainVector[k] = pCryptKey->abChainVector[k+1];
2397 pCryptKey->abChainVector[k] = in[j];
2398 }
2399 break;
2400
2401 default:
2403 return FALSE;
2404 }
2405 memcpy(in, out, pCryptKey->dwBlockLen);
2406 }
2407 if (Final) {
2408 if (pbData[*pdwDataLen-1] &&
2409 pbData[*pdwDataLen-1] <= pCryptKey->dwBlockLen &&
2410 pbData[*pdwDataLen-1] <= *pdwDataLen) {
2411 BOOL padOkay = TRUE;
2412
2413 /* check that every bad byte has the same value */
2414 for (i = 1; padOkay && i < pbData[*pdwDataLen-1]; i++)
2415 if (pbData[*pdwDataLen - i - 1] != pbData[*pdwDataLen - 1])
2416 padOkay = FALSE;
2417 if (padOkay)
2419 else {
2421 setup_key(pCryptKey);
2422 return FALSE;
2423 }
2424 }
2425 else {
2427 setup_key(pCryptKey);
2428 return FALSE;
2429 }
2430 }
2431
2432 } else if (GET_ALG_TYPE(pCryptKey->aiAlgid) == ALG_TYPE_STREAM) {
2433 encrypt_stream_impl(pCryptKey->aiAlgid, &pCryptKey->context, pbData, *pdwDataLen);
2434 } else if (GET_ALG_TYPE(pCryptKey->aiAlgid) == ALG_TYPE_RSA) {
2435 if (pCryptKey->aiAlgid == CALG_RSA_SIGN) {
2437 return FALSE;
2438 }
2439 encrypt_block_impl(pCryptKey->aiAlgid, PK_PRIVATE, &pCryptKey->context, pbData, pbData, RSAENH_DECRYPT);
2440 if (!unpad_data(pbData, pCryptKey->dwBlockLen, pbData, pdwDataLen, dwFlags)) return FALSE;
2441 Final = TRUE;
2442 } else {
2444 return FALSE;
2445 }
2446
2447 if (Final) setup_key(pCryptKey);
2448
2450 if (*pdwDataLen>dwMax ||
2452 }
2453
2454 return TRUE;
2455}
#define RSAENH_KEYSTATE_IDLE
Definition: rsaenh.c:85
#define RSAENH_KEYSTATE_ENCRYPTING
Definition: rsaenh.c:86
#define RSAENH_MAX_BLOCK_SIZE
Definition: rsaenh.c:84
BOOL WINAPI RSAENH_CPHashData(HCRYPTPROV hProv, HCRYPTHASH hHash, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
Definition: rsaenh.c:4164
GLuint in
Definition: glext.h:9616
BOOL encrypt_stream_impl(ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext, BYTE *stream, DWORD dwLen)
Definition: implglue.c:381
int k
Definition: mpi.c:3369
static FILE * out
Definition: regtests2xml.c:44
_In_ HCRYPTHASH _In_ BOOL Final
Definition: wincrypt.h:4199
#define CRYPT_MODE_ECB
Definition: wincrypt.h:2191
#define ALG_TYPE_RSA
Definition: wincrypt.h:1724
_In_ HCRYPTHASH hHash
Definition: wincrypt.h:4198
#define CRYPT_MODE_CFB
Definition: wincrypt.h:2193
#define ALG_TYPE_STREAM
Definition: wincrypt.h:1726

◆ RSAENH_CPDeriveKey()

BOOL WINAPI RSAENH_CPDeriveKey ( HCRYPTPROV  hProv,
ALG_ID  Algid,
HCRYPTHASH  hBaseData,
DWORD  dwFlags,
HCRYPTKEY phKey 
)

Definition at line 3922 of file rsaenh.c.

3924{
3925 CRYPTKEY *pCryptKey, *pMasterKey;
3926 CRYPTHASH *pCryptHash;
3927 BYTE abHashValue[RSAENH_MAX_HASH_SIZE*2];
3928 DWORD dwLen;
3929
3930 TRACE("(hProv=%08lx, Algid=%d, hBaseData=%08lx, dwFlags=%08x phKey=%p)\n", hProv, Algid,
3931 hBaseData, dwFlags, phKey);
3932
3934 {
3936 return FALSE;
3937 }
3938
3940 (OBJECTHDR**)&pCryptHash))
3941 {
3943 return FALSE;
3944 }
3945
3946 if (!phKey)
3947 {
3949 return FALSE;
3950 }
3951
3952 switch (GET_ALG_CLASS(Algid))
3953 {
3955 {
3956 int need_padding, copy_len;
3957 *phKey = new_key(hProv, Algid, dwFlags, &pCryptKey);
3958 if (*phKey == (HCRYPTKEY)INVALID_HANDLE_VALUE) return FALSE;
3959
3960 /*
3961 * We derive the key material from the hash.
3962 * If the hash value is not large enough for the claimed key, we have to construct
3963 * a larger binary value based on the hash. This is documented in MSDN: CryptDeriveKey.
3964 */
3965 dwLen = RSAENH_MAX_HASH_SIZE;
3966 RSAENH_CPGetHashParam(pCryptHash->hProv, hBaseData, HP_HASHVAL, abHashValue, &dwLen, 0);
3967
3968 /*
3969 * The usage of padding seems to vary from algorithm to algorithm.
3970 * For now the only different case found was for AES with 128 bit key.
3971 */
3972 switch(Algid)
3973 {
3974 case CALG_AES_128:
3975 /* To reduce the chance of regressions we will only deviate
3976 * from the old behavior for the tested hash lengths */
3977 if (dwLen == 16 || dwLen == 20)
3978 {
3979 need_padding = 1;
3980 break;
3981 }
3982 default:
3983 need_padding = dwLen < pCryptKey->dwKeyLen;
3984 }
3985
3986 copy_len = pCryptKey->dwKeyLen;
3987 if (need_padding)
3988 {
3990 BYTE old_hashval[RSAENH_MAX_HASH_SIZE];
3991 DWORD i;
3992
3993 memcpy(old_hashval, pCryptHash->abHashValue, RSAENH_MAX_HASH_SIZE);
3994
3995 for (i=0; i<RSAENH_HMAC_DEF_PAD_LEN; i++) {
3996 pad1[i] = RSAENH_HMAC_DEF_IPAD_CHAR ^ (i<dwLen ? abHashValue[i] : 0);
3997 pad2[i] = RSAENH_HMAC_DEF_OPAD_CHAR ^ (i<dwLen ? abHashValue[i] : 0);
3998 }
3999
4000 init_hash(pCryptHash);
4001 update_hash(pCryptHash, pad1, RSAENH_HMAC_DEF_PAD_LEN);
4002 finalize_hash(pCryptHash);
4003 memcpy(abHashValue, pCryptHash->abHashValue, pCryptHash->dwHashSize);
4004
4005 init_hash(pCryptHash);
4006 update_hash(pCryptHash, pad2, RSAENH_HMAC_DEF_PAD_LEN);
4007 finalize_hash(pCryptHash);
4008 memcpy(abHashValue+pCryptHash->dwHashSize, pCryptHash->abHashValue,
4009 pCryptHash->dwHashSize);
4010
4011 memcpy(pCryptHash->abHashValue, old_hashval, RSAENH_MAX_HASH_SIZE);
4012 }
4013 /*
4014 * Padding was not required, we have more hash than needed.
4015 * Do we need to use the remaining hash as salt?
4016 */
4017 else if((dwFlags & CRYPT_CREATE_SALT) &&
4018 (Algid == CALG_RC2 || Algid == CALG_RC4))
4019 {
4020 copy_len += pCryptKey->dwSaltLen;
4021 }
4022
4023 memcpy(pCryptKey->abKeyValue, abHashValue,
4024 RSAENH_MIN(copy_len, sizeof(pCryptKey->abKeyValue)));
4025 break;
4026 }
4028 if (!lookup_handle(&handle_table, pCryptHash->hKey, RSAENH_MAGIC_KEY,
4029 (OBJECTHDR**)&pMasterKey))
4030 {
4031 SetLastError(NTE_FAIL); /* FIXME error code */
4032 return FALSE;
4033 }
4034
4035 switch (Algid)
4036 {
4037 /* See RFC 2246, chapter 6.3 Key calculation */
4039 if (!pMasterKey->siSChannelInfo.saEncAlg.Algid ||
4040 !pMasterKey->siSChannelInfo.saEncAlg.cBits)
4041 {
4043 return FALSE;
4044 }
4045 *phKey = new_key(hProv, pMasterKey->siSChannelInfo.saEncAlg.Algid,
4046 MAKELONG(LOWORD(dwFlags),pMasterKey->siSChannelInfo.saEncAlg.cBits),
4047 &pCryptKey);
4048 if (*phKey == (HCRYPTKEY)INVALID_HANDLE_VALUE) return FALSE;
4049 memcpy(pCryptKey->abKeyValue,
4050 pCryptHash->abHashValue + (
4051 2 * (pMasterKey->siSChannelInfo.saMACAlg.cBits / 8) +
4052 ((dwFlags & CRYPT_SERVER) ?
4053 (pMasterKey->siSChannelInfo.saEncAlg.cBits / 8) : 0)),
4054 pMasterKey->siSChannelInfo.saEncAlg.cBits / 8);
4055 memcpy(pCryptKey->abInitVector,
4056 pCryptHash->abHashValue + (
4057 2 * (pMasterKey->siSChannelInfo.saMACAlg.cBits / 8) +
4058 2 * (pMasterKey->siSChannelInfo.saEncAlg.cBits / 8) +
4059 ((dwFlags & CRYPT_SERVER) ? pCryptKey->dwBlockLen : 0)),
4060 pCryptKey->dwBlockLen);
4061 break;
4062
4064 *phKey = new_key(hProv, Algid,
4065 MAKELONG(LOWORD(dwFlags),pMasterKey->siSChannelInfo.saMACAlg.cBits),
4066 &pCryptKey);
4067 if (*phKey == (HCRYPTKEY)INVALID_HANDLE_VALUE) return FALSE;
4068 memcpy(pCryptKey->abKeyValue,
4069 pCryptHash->abHashValue + ((dwFlags & CRYPT_SERVER) ?
4070 pMasterKey->siSChannelInfo.saMACAlg.cBits / 8 : 0),
4071 pMasterKey->siSChannelInfo.saMACAlg.cBits / 8);
4072 break;
4073
4074 default:
4076 return FALSE;
4077 }
4078 break;
4079
4080 default:
4082 return FALSE;
4083 }
4084
4085 setup_key(pCryptKey);
4086 return TRUE;
4087}
BOOL WINAPI RSAENH_CPGetHashParam(HCRYPTPROV hProv, HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
Definition: rsaenh.c:3291
static void finalize_hash(CRYPTHASH *pCryptHash)
Definition: rsaenh.c:706
static void update_hash(CRYPTHASH *pCryptHash, const BYTE *pbData, DWORD dwDataLen)
Definition: rsaenh.c:671
#define LOWORD(l)
Definition: pedump.c:82
#define CALG_SCHANNEL_MAC_KEY
Definition: wincrypt.h:1845
#define CRYPT_SERVER
Definition: wincrypt.h:2212
#define CALG_SCHANNEL_ENC_KEY
Definition: wincrypt.h:1846
#define HP_HASHVAL
Definition: wincrypt.h:2183
#define NTE_FAIL
Definition: winerror.h:2900
#define NTE_BAD_HASH
Definition: winerror.h:2870

◆ RSAENH_CPDestroyHash()

BOOL WINAPI RSAENH_CPDestroyHash ( HCRYPTPROV  hProv,
HCRYPTHASH  hHash 
)

Definition at line 1990 of file rsaenh.c.

1991{
1992 TRACE("(hProv=%08lx, hHash=%08lx)\n", hProv, hHash);
1993
1995 {
1997 return FALSE;
1998 }
1999
2001 {
2003 return FALSE;
2004 }
2005
2006 return TRUE;
2007}

Referenced by RSAENH_CPSetHashParam(), and tls1_prf().

◆ RSAENH_CPDestroyKey()

BOOL WINAPI RSAENH_CPDestroyKey ( HCRYPTPROV  hProv,
HCRYPTKEY  hKey 
)

Definition at line 2023 of file rsaenh.c.

2024{
2025 TRACE("(hProv=%08lx, hKey=%08lx)\n", hProv, hKey);
2026
2028 {
2030 return FALSE;
2031 }
2032
2034 {
2036 return FALSE;
2037 }
2038
2039 return TRUE;
2040}

Referenced by release_and_install_key(), and RSAENH_CPSignHash().

◆ RSAENH_CPDuplicateHash()

BOOL WINAPI RSAENH_CPDuplicateHash ( HCRYPTPROV  hUID,
HCRYPTHASH  hHash,
DWORD pdwReserved,
DWORD  dwFlags,
HCRYPTHASH phHash 
)

Definition at line 2058 of file rsaenh.c.

2060{
2061 CRYPTHASH *pSrcHash, *pDestHash;
2062
2063 TRACE("(hUID=%08lx, hHash=%08lx, pdwReserved=%p, dwFlags=%08x, phHash=%p)\n", hUID, hHash,
2064 pdwReserved, dwFlags, phHash);
2065
2067 {
2069 return FALSE;
2070 }
2071
2073 {
2075 return FALSE;
2076 }
2077
2078 if (!phHash || pdwReserved || dwFlags)
2079 {
2081 return FALSE;
2082 }
2083
2085 destroy_hash, (OBJECTHDR**)&pDestHash);
2086 if (*phHash != (HCRYPTHASH)INVALID_HANDLE_VALUE)
2087 {
2088 *pDestHash = *pSrcHash;
2089 duplicate_hash_impl(pSrcHash->aiAlgid, &pSrcHash->context, &pDestHash->context);
2090 copy_hmac_info(&pDestHash->pHMACInfo, pSrcHash->pHMACInfo);
2091 copy_data_blob(&pDestHash->tpPRFParams.blobLabel, &pSrcHash->tpPRFParams.blobLabel);
2092 copy_data_blob(&pDestHash->tpPRFParams.blobSeed, &pSrcHash->tpPRFParams.blobSeed);
2093 }
2094
2095 return *phHash != (HCRYPTHASH)INVALID_HANDLE_VALUE;
2096}
static BOOL copy_hmac_info(PHMAC_INFO *dst, const HMAC_INFO *src)
Definition: rsaenh.c:573
BOOL duplicate_hash_impl(ALG_ID aiAlgid, const HASH_CONTEXT *pSrcHashContext, HASH_CONTEXT *pDestHashContext)
Definition: implglue.c:173
_Reserved_ DWORD * pdwReserved
Definition: wincrypt.h:4254
ULONG_PTR HCRYPTHASH
Definition: wincrypt.h:50

◆ RSAENH_CPDuplicateKey()

BOOL WINAPI RSAENH_CPDuplicateKey ( HCRYPTPROV  hUID,
HCRYPTKEY  hKey,
DWORD pdwReserved,
DWORD  dwFlags,
HCRYPTKEY phKey 
)

Definition at line 2114 of file rsaenh.c.

2116{
2117 CRYPTKEY *pSrcKey, *pDestKey;
2118
2119 TRACE("(hUID=%08lx, hKey=%08lx, pdwReserved=%p, dwFlags=%08x, phKey=%p)\n", hUID, hKey,
2120 pdwReserved, dwFlags, phKey);
2121
2123 {
2125 return FALSE;
2126 }
2127
2129 {
2131 return FALSE;
2132 }
2133
2134 if (!phKey || pdwReserved || dwFlags)
2135 {
2137 return FALSE;
2138 }
2139
2141 (OBJECTHDR**)&pDestKey);
2142 if (*phKey != (HCRYPTKEY)INVALID_HANDLE_VALUE)
2143 {
2144 *pDestKey = *pSrcKey;
2146 &pSrcKey->siSChannelInfo.blobServerRandom);
2148 &pSrcKey->siSChannelInfo.blobClientRandom);
2149 duplicate_key_impl(pSrcKey->aiAlgid, &pSrcKey->context, &pDestKey->context);
2150 return TRUE;
2151 }
2152 else
2153 {
2154 return FALSE;
2155 }
2156}
BOOL duplicate_key_impl(ALG_ID aiAlgid, const KEY_CONTEXT *pSrcKeyContext, KEY_CONTEXT *pDestKeyContext)
Definition: implglue.c:255

◆ RSAENH_CPEncrypt()

BOOL WINAPI RSAENH_CPEncrypt ( HCRYPTPROV  hProv,
HCRYPTKEY  hKey,
HCRYPTHASH  hHash,
BOOL  Final,
DWORD  dwFlags,
BYTE pbData,
DWORD pdwDataLen,
DWORD  dwBufLen 
)

Definition at line 2183 of file rsaenh.c.

2185{
2186 CRYPTKEY *pCryptKey;
2188 DWORD dwEncryptedLen, i, j, k;
2189
2190 TRACE("(hProv=%08lx, hKey=%08lx, hHash=%08lx, Final=%d, dwFlags=%08x, pbData=%p, "
2191 "pdwDataLen=%p, dwBufLen=%d)\n", hProv, hKey, hHash, Final, dwFlags, pbData, pdwDataLen,
2192 dwBufLen);
2193
2195 {
2197 return FALSE;
2198 }
2199
2200 if (dwFlags)
2201 {
2203 return FALSE;
2204 }
2205
2207 {
2209 return FALSE;
2210 }
2211
2212 if (pCryptKey->dwState == RSAENH_KEYSTATE_IDLE)
2213 pCryptKey->dwState = RSAENH_KEYSTATE_ENCRYPTING;
2214
2215 if (pCryptKey->dwState != RSAENH_KEYSTATE_ENCRYPTING)
2216 {
2218 return FALSE;
2219 }
2220
2222 if (!RSAENH_CPHashData(hProv, hHash, pbData, *pdwDataLen, 0)) return FALSE;
2223 }
2224
2225 if (GET_ALG_TYPE(pCryptKey->aiAlgid) == ALG_TYPE_BLOCK) {
2226 if (!Final && (*pdwDataLen % pCryptKey->dwBlockLen)) {
2228 return FALSE;
2229 }
2230
2231 dwEncryptedLen = (*pdwDataLen/pCryptKey->dwBlockLen+(Final?1:0))*pCryptKey->dwBlockLen;
2232
2233 if (pbData == NULL) {
2234 *pdwDataLen = dwEncryptedLen;
2235 return TRUE;
2236 }
2237 else if (dwEncryptedLen > dwBufLen) {
2238 *pdwDataLen = dwEncryptedLen;
2240 return FALSE;
2241 }
2242
2243 /* Pad final block with length bytes */
2244 for (i=*pdwDataLen; i<dwEncryptedLen; i++) pbData[i] = dwEncryptedLen - *pdwDataLen;
2245 *pdwDataLen = dwEncryptedLen;
2246
2247 for (i=0, in=pbData; i<*pdwDataLen; i+=pCryptKey->dwBlockLen, in+=pCryptKey->dwBlockLen) {
2248 switch (pCryptKey->dwMode) {
2249 case CRYPT_MODE_ECB:
2250 encrypt_block_impl(pCryptKey->aiAlgid, 0, &pCryptKey->context, in, out,
2252 break;
2253
2254 case CRYPT_MODE_CBC:
2255 for (j=0; j<pCryptKey->dwBlockLen; j++) in[j] ^= pCryptKey->abChainVector[j];
2256 encrypt_block_impl(pCryptKey->aiAlgid, 0, &pCryptKey->context, in, out,
2258 memcpy(pCryptKey->abChainVector, out, pCryptKey->dwBlockLen);
2259 break;
2260
2261 case CRYPT_MODE_CFB:
2262 for (j=0; j<pCryptKey->dwBlockLen; j++) {
2263 encrypt_block_impl(pCryptKey->aiAlgid, 0, &pCryptKey->context,
2264 pCryptKey->abChainVector, o, RSAENH_ENCRYPT);
2265 out[j] = in[j] ^ o[0];
2266 for (k=0; k<pCryptKey->dwBlockLen-1; k++)
2267 pCryptKey->abChainVector[k] = pCryptKey->abChainVector[k+1];
2268 pCryptKey->abChainVector[k] = out[j];
2269 }
2270 break;
2271
2272 default:
2274 return FALSE;
2275 }
2276 memcpy(in, out, pCryptKey->dwBlockLen);
2277 }
2278 } else if (GET_ALG_TYPE(pCryptKey->aiAlgid) == ALG_TYPE_STREAM) {
2279 if (pbData == NULL) {
2281 return TRUE;
2282 }
2283 encrypt_stream_impl(pCryptKey->aiAlgid, &pCryptKey->context, pbData, *pdwDataLen);
2284 } else if (GET_ALG_TYPE(pCryptKey->aiAlgid) == ALG_TYPE_RSA) {
2285 if (pCryptKey->aiAlgid == CALG_RSA_SIGN) {
2287 return FALSE;
2288 }
2289 if (!pbData) {
2290 *pdwDataLen = pCryptKey->dwBlockLen;
2291 return TRUE;
2292 }
2293 if (dwBufLen < pCryptKey->dwBlockLen) {
2295 return FALSE;
2296 }
2297 if (!pad_data(pbData, *pdwDataLen, pbData, pCryptKey->dwBlockLen, dwFlags)) return FALSE;
2298 encrypt_block_impl(pCryptKey->aiAlgid, PK_PUBLIC, &pCryptKey->context, pbData, pbData, RSAENH_ENCRYPT);
2299 *pdwDataLen = pCryptKey->dwBlockLen;
2300 Final = TRUE;
2301 } else {
2303 return FALSE;
2304 }
2305
2306 if (Final) setup_key(pCryptKey);
2307
2308 return TRUE;
2309}
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_ DWORD _In_ DWORD dwBufLen
Definition: wincrypt.h:4246

Referenced by finalize_hash(), and update_hash().

◆ RSAENH_CPExportKey()

BOOL WINAPI RSAENH_CPExportKey ( HCRYPTPROV  hProv,
HCRYPTKEY  hKey,
HCRYPTKEY  hPubKey,
DWORD  dwBlobType,
DWORD  dwFlags,
BYTE pbData,
DWORD pdwDataLen 
)

Definition at line 2682 of file rsaenh.c.

2684{
2685 CRYPTKEY *pCryptKey;
2686
2687 TRACE("(hProv=%08lx, hKey=%08lx, hPubKey=%08lx, dwBlobType=%08x, dwFlags=%08x, pbData=%p,"
2688 "pdwDataLen=%p)\n", hProv, hKey, hPubKey, dwBlobType, dwFlags, pbData, pdwDataLen);
2689
2691 {
2693 return FALSE;
2694 }
2695
2697 {
2699 return FALSE;
2700 }
2701
2702 return crypt_export_key(pCryptKey, hPubKey, dwBlobType, dwFlags, FALSE,
2704}
static BOOL crypt_export_key(CRYPTKEY *pCryptKey, HCRYPTKEY hPubKey, DWORD dwBlobType, DWORD dwFlags, BOOL force, BYTE *pbData, DWORD *pdwDataLen)
Definition: rsaenh.c:2621

◆ RSAENH_CPGenKey()

BOOL WINAPI RSAENH_CPGenKey ( HCRYPTPROV  hProv,
ALG_ID  Algid,
DWORD  dwFlags,
HCRYPTKEY phKey 
)

Definition at line 3163 of file rsaenh.c.

3164{
3165 KEYCONTAINER *pKeyContainer;
3166 CRYPTKEY *pCryptKey;
3167
3168 TRACE("(hProv=%08lx, aiAlgid=%d, dwFlags=%08x, phKey=%p)\n", hProv, Algid, dwFlags, phKey);
3169
3170 if (!(pKeyContainer = get_key_container(hProv)))
3171 {
3172 /* MSDN: hProv not containing valid context handle */
3173 return FALSE;
3174 }
3175
3176 switch (Algid)
3177 {
3178 case AT_SIGNATURE:
3179 case CALG_RSA_SIGN:
3180 *phKey = new_key(hProv, CALG_RSA_SIGN, dwFlags, &pCryptKey);
3181 if (pCryptKey) {
3182 new_key_impl(pCryptKey->aiAlgid, &pCryptKey->context, pCryptKey->dwKeyLen);
3183 setup_key(pCryptKey);
3185 &pKeyContainer->hSignatureKeyPair,
3186 FALSE);
3187 }
3188 break;
3189
3190 case AT_KEYEXCHANGE:
3191 case CALG_RSA_KEYX:
3192 *phKey = new_key(hProv, CALG_RSA_KEYX, dwFlags, &pCryptKey);
3193 if (pCryptKey) {
3194 new_key_impl(pCryptKey->aiAlgid, &pCryptKey->context, pCryptKey->dwKeyLen);
3195 setup_key(pCryptKey);
3197 &pKeyContainer->hKeyExchangeKeyPair,
3198 FALSE);
3199 }
3200 break;
3201
3202 case CALG_RC2:
3203 case CALG_RC4:
3204 case CALG_DES:
3205 case CALG_3DES_112:
3206 case CALG_3DES:
3207 case CALG_AES:
3208 case CALG_AES_128:
3209 case CALG_AES_192:
3210 case CALG_AES_256:
3211 case CALG_PCT1_MASTER:
3212 case CALG_SSL2_MASTER:
3213 case CALG_SSL3_MASTER:
3214 case CALG_TLS1_MASTER:
3215 *phKey = new_key(hProv, Algid, dwFlags, &pCryptKey);
3216 if (pCryptKey) {
3218 switch (Algid) {
3219 case CALG_SSL3_MASTER:
3220 pCryptKey->abKeyValue[0] = RSAENH_SSL3_VERSION_MAJOR;
3221 pCryptKey->abKeyValue[1] = RSAENH_SSL3_VERSION_MINOR;
3222 break;
3223
3224 case CALG_TLS1_MASTER:
3225 pCryptKey->abKeyValue[0] = RSAENH_TLS1_VERSION_MAJOR;
3226 pCryptKey->abKeyValue[1] = RSAENH_TLS1_VERSION_MINOR;
3227 break;
3228 }
3229 setup_key(pCryptKey);
3230 }
3231 break;
3232
3233 default:
3234 /* MSDN: Algorithm not supported specified by Algid */
3236 return FALSE;
3237 }
3238
3239 return *phKey != (HCRYPTKEY)INVALID_HANDLE_VALUE;
3240}
#define RSAENH_SSL3_VERSION_MINOR
Definition: rsaenh.c:159
#define RSAENH_TLS1_VERSION_MINOR
Definition: rsaenh.c:161
#define RSAENH_SSL3_VERSION_MAJOR
Definition: rsaenh.c:158
#define RSAENH_TLS1_VERSION_MAJOR
Definition: rsaenh.c:160
BOOL new_key_impl(ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext, DWORD dwKeyLen)
Definition: implglue.c:181

◆ RSAENH_CPGenRandom()

BOOL WINAPI RSAENH_CPGenRandom ( HCRYPTPROV  hProv,
DWORD  dwLen,
BYTE pbBuffer 
)

Definition at line 3256 of file rsaenh.c.

3257{
3258 TRACE("(hProv=%08lx, dwLen=%d, pbBuffer=%p)\n", hProv, dwLen, pbBuffer);
3259
3261 {
3262 /* MSDN: hProv not containing valid context handle */
3264 return FALSE;
3265 }
3266
3267 return gen_rand_impl(pbBuffer, dwLen);
3268}

◆ RSAENH_CPGetHashParam()

BOOL WINAPI RSAENH_CPGetHashParam ( HCRYPTPROV  hProv,
HCRYPTHASH  hHash,
DWORD  dwParam,
BYTE pbData,
DWORD pdwDataLen,
DWORD  dwFlags 
)

Definition at line 3291 of file rsaenh.c.

3293{
3294 CRYPTHASH *pCryptHash;
3295
3296 TRACE("(hProv=%08lx, hHash=%08lx, dwParam=%08x, pbData=%p, pdwDataLen=%p, dwFlags=%08x)\n",
3297 hProv, hHash, dwParam, pbData, pdwDataLen, dwFlags);
3298
3300 {
3302 return FALSE;
3303 }
3304
3305 if (dwFlags)
3306 {
3308 return FALSE;
3309 }
3310
3312 (OBJECTHDR**)&pCryptHash))
3313 {
3315 return FALSE;
3316 }
3317
3318 if (!pdwDataLen)
3319 {
3321 return FALSE;
3322 }
3323
3324 switch (dwParam)
3325 {
3326 case HP_ALGID:
3327 return copy_param(pbData, pdwDataLen, (const BYTE*)&pCryptHash->aiAlgid,
3328 sizeof(ALG_ID));
3329
3330 case HP_HASHSIZE:
3331 return copy_param(pbData, pdwDataLen, (const BYTE*)&pCryptHash->dwHashSize,
3332 sizeof(DWORD));
3333
3334 case HP_HASHVAL:
3335 if (pCryptHash->aiAlgid == CALG_TLS1PRF) {
3336 return tls1_prf(hProv, pCryptHash->hKey, &pCryptHash->tpPRFParams.blobLabel,
3337 &pCryptHash->tpPRFParams.blobSeed, pbData, *pdwDataLen);
3338 }
3339
3340 if ( pbData == NULL ) {
3341 *pdwDataLen = pCryptHash->dwHashSize;
3342 return TRUE;
3343 }
3344
3345 if (pbData && (pCryptHash->dwState != RSAENH_HASHSTATE_FINISHED))
3346 {
3347 finalize_hash(pCryptHash);
3348 pCryptHash->dwState = RSAENH_HASHSTATE_FINISHED;
3349 }
3350
3351 return copy_param(pbData, pdwDataLen, pCryptHash->abHashValue,
3352 pCryptHash->dwHashSize);
3353
3354 default:
3356 return FALSE;
3357 }
3358}
static BOOL copy_param(BYTE *pbBuffer, DWORD *pdwBufferSize, const BYTE *pbParam, DWORD dwParamSize)
Definition: rsaenh.c:403
#define RSAENH_HASHSTATE_FINISHED
Definition: rsaenh.c:58
#define HP_HASHSIZE
Definition: wincrypt.h:2184
#define HP_ALGID
Definition: wincrypt.h:2182

Referenced by RSAENH_CPDeriveKey(), RSAENH_CPSetHashParam(), RSAENH_CPSignHash(), and RSAENH_CPVerifySignature().

◆ RSAENH_CPGetKeyParam()

BOOL WINAPI RSAENH_CPGetKeyParam ( HCRYPTPROV  hProv,
HCRYPTKEY  hKey,
DWORD  dwParam,
BYTE pbData,
DWORD pdwDataLen,
DWORD  dwFlags 
)

Definition at line 3601 of file rsaenh.c.

3603{
3604 CRYPTKEY *pCryptKey;
3605 DWORD dwValue;
3606
3607 TRACE("(hProv=%08lx, hKey=%08lx, dwParam=%08x, pbData=%p, pdwDataLen=%p dwFlags=%08x)\n",
3608 hProv, hKey, dwParam, pbData, pdwDataLen, dwFlags);
3609
3611 {
3613 return FALSE;
3614 }
3615
3616 if (dwFlags) {
3618 return FALSE;
3619 }
3620
3622 {
3624 return FALSE;
3625 }
3626
3627 switch (dwParam)
3628 {
3629 case KP_IV:
3630 return copy_param(pbData, pdwDataLen, pCryptKey->abInitVector,
3631 pCryptKey->dwBlockLen);
3632
3633 case KP_SALT:
3634 switch (pCryptKey->aiAlgid) {
3635 case CALG_RC2:
3636 case CALG_RC4:
3638 &pCryptKey->abKeyValue[pCryptKey->dwKeyLen],
3639 pCryptKey->dwSaltLen);
3640 default:
3642 return FALSE;
3643 }
3644
3645 case KP_PADDING:
3646 dwValue = PKCS5_PADDING;
3647 return copy_param(pbData, pdwDataLen, (const BYTE*)&dwValue, sizeof(DWORD));
3648
3649 case KP_KEYLEN:
3650 dwValue = pCryptKey->dwKeyLen << 3;
3651 return copy_param(pbData, pdwDataLen, (const BYTE*)&dwValue, sizeof(DWORD));
3652
3654 if (pCryptKey->dwEffectiveKeyLen)
3655 dwValue = pCryptKey->dwEffectiveKeyLen;
3656 else
3657 dwValue = pCryptKey->dwKeyLen << 3;
3658 return copy_param(pbData, pdwDataLen, (const BYTE*)&dwValue, sizeof(DWORD));
3659
3660 case KP_BLOCKLEN:
3661 dwValue = pCryptKey->dwBlockLen << 3;
3662 return copy_param(pbData, pdwDataLen, (const BYTE*)&dwValue, sizeof(DWORD));
3663
3664 case KP_MODE:
3665 return copy_param(pbData, pdwDataLen, (const BYTE*)&pCryptKey->dwMode, sizeof(DWORD));
3666
3667 case KP_MODE_BITS:
3668 return copy_param(pbData, pdwDataLen, (const BYTE*)&pCryptKey->dwModeBits,
3669 sizeof(DWORD));
3670
3671 case KP_PERMISSIONS:
3672 return copy_param(pbData, pdwDataLen, (const BYTE*)&pCryptKey->dwPermissions,
3673 sizeof(DWORD));
3674
3675 case KP_ALGID:
3676 return copy_param(pbData, pdwDataLen, (const BYTE*)&pCryptKey->aiAlgid, sizeof(DWORD));
3677
3678 default:
3680 return FALSE;
3681 }
3682}
#define KP_MODE
Definition: wincrypt.h:2131
#define KP_IV
Definition: wincrypt.h:2128
#define KP_SALT
Definition: wincrypt.h:2129
#define KP_PADDING
Definition: wincrypt.h:2130
#define KP_EFFECTIVE_KEYLEN
Definition: wincrypt.h:2146
#define KP_ALGID
Definition: wincrypt.h:2134
#define KP_MODE_BITS
Definition: wincrypt.h:2132
#define PKCS5_PADDING
Definition: wincrypt.h:2172
#define KP_KEYLEN
Definition: wincrypt.h:2136
#define KP_PERMISSIONS
Definition: wincrypt.h:2133

Referenced by init_hash().

◆ RSAENH_CPGetProvParam()

BOOL WINAPI RSAENH_CPGetProvParam ( HCRYPTPROV  hProv,
DWORD  dwParam,
BYTE pbData,
DWORD pdwDataLen,
DWORD  dwFlags 
)

Definition at line 3708 of file rsaenh.c.

3710{
3711 KEYCONTAINER *pKeyContainer;
3712 PROV_ENUMALGS provEnumalgs;
3713 DWORD dwTemp;
3714 HKEY hKey;
3715
3716 /* This is for dwParam PP_CRYPT_COUNT_KEY_USE.
3717 * IE6 SP1 asks for it in the 'About' dialog.
3718 * Returning this BLOB seems to satisfy IE. The marked 0x00 seem
3719 * to be 'don't care's. If you know anything more specific about
3720 * this provider parameter, please report to wine-devel@winehq.org */
3721 static const BYTE abWTF[96] = {
3722 0xb0, 0x25, 0x63, 0x86, 0x9c, 0xab, 0xb6, 0x37,
3723 0xe8, 0x82, 0x00, 0x72, 0x06, 0xb2, 0x00, 0x3b,
3724 0x60, 0x35, 0x00, 0x3b, 0x88, 0xce, 0x00, 0x82,
3725 0xbc, 0x7a, 0x00, 0xb7, 0x4f, 0x7e, 0x00, 0xde,
3726 0x92, 0xf1, 0x00, 0x83, 0xea, 0x5e, 0x00, 0xc8,
3727 0x12, 0x1e, 0xd4, 0x06, 0xf7, 0x66, 0x00, 0x01,
3728 0x29, 0xa4, 0x00, 0xf8, 0x24, 0x0c, 0x00, 0x33,
3729 0x06, 0x80, 0x00, 0x02, 0x46, 0x0b, 0x00, 0x6d,
3730 0x5b, 0xca, 0x00, 0x9a, 0x10, 0xf0, 0x00, 0x05,
3731 0x19, 0xd0, 0x00, 0x2c, 0xf6, 0x27, 0x00, 0xaa,
3732 0x7c, 0x6f, 0x00, 0xb9, 0xd8, 0x72, 0x00, 0x03,
3733 0xf3, 0x81, 0x00, 0xfa, 0xe8, 0x26, 0x00, 0xca
3734 };
3735
3736 TRACE("(hProv=%08lx, dwParam=%08x, pbData=%p, pdwDataLen=%p, dwFlags=%08x)\n",
3737 hProv, dwParam, pbData, pdwDataLen, dwFlags);
3738
3739 if (!pdwDataLen) {
3741 return FALSE;
3742 }
3743
3744 if (!(pKeyContainer = get_key_container(hProv)))
3745 {
3746 /* MSDN: hProv not containing valid context handle */
3747 return FALSE;
3748 }
3749
3750 switch (dwParam)
3751 {
3752 case PP_CONTAINER:
3753 case PP_UNIQUE_CONTAINER:/* MSDN says we can return the same value as PP_CONTAINER */
3754 return copy_param(pbData, pdwDataLen, (const BYTE*)pKeyContainer->szName,
3755 strlen(pKeyContainer->szName)+1);
3756
3757 case PP_NAME:
3758 return copy_param(pbData, pdwDataLen, (const BYTE*)pKeyContainer->szProvName,
3759 strlen(pKeyContainer->szProvName)+1);
3760
3761 case PP_PROVTYPE:
3762 dwTemp = PROV_RSA_FULL;
3763 return copy_param(pbData, pdwDataLen, (const BYTE*)&dwTemp, sizeof(dwTemp));
3764
3765 case PP_KEYSPEC:
3766 dwTemp = AT_SIGNATURE | AT_KEYEXCHANGE;
3767 return copy_param(pbData, pdwDataLen, (const BYTE*)&dwTemp, sizeof(dwTemp));
3768
3769 case PP_KEYSET_TYPE:
3770 dwTemp = pKeyContainer->dwFlags & CRYPT_MACHINE_KEYSET;
3771 return copy_param(pbData, pdwDataLen, (const BYTE*)&dwTemp, sizeof(dwTemp));
3772
3773 case PP_KEYSTORAGE:
3774 dwTemp = CRYPT_SEC_DESCR;
3775 return copy_param(pbData, pdwDataLen, (const BYTE*)&dwTemp, sizeof(dwTemp));
3776
3777 case PP_SIG_KEYSIZE_INC:
3779 dwTemp = 8;
3780 return copy_param(pbData, pdwDataLen, (const BYTE*)&dwTemp, sizeof(dwTemp));
3781
3782 case PP_IMPTYPE:
3783 dwTemp = CRYPT_IMPL_SOFTWARE;
3784 return copy_param(pbData, pdwDataLen, (const BYTE*)&dwTemp, sizeof(dwTemp));
3785
3786 case PP_VERSION:
3787 dwTemp = 0x00000200;
3788 return copy_param(pbData, pdwDataLen, (const BYTE*)&dwTemp, sizeof(dwTemp));
3789
3790 case PP_ENUMCONTAINERS:
3791 if ((dwFlags & CRYPT_FIRST) == CRYPT_FIRST) pKeyContainer->dwEnumContainersCtr = 0;
3792
3793 if (!pbData) {
3794 *pdwDataLen = (DWORD)MAX_PATH + 1;
3795 return TRUE;
3796 }
3797
3799 {
3801 return FALSE;
3802 }
3803
3804 dwTemp = *pdwDataLen;
3805 switch (RegEnumKeyExA(hKey, pKeyContainer->dwEnumContainersCtr, (LPSTR)pbData, &dwTemp,
3806 NULL, NULL, NULL, NULL))
3807 {
3808 case ERROR_MORE_DATA:
3809 *pdwDataLen = (DWORD)MAX_PATH + 1;
3810
3811 case ERROR_SUCCESS:
3812 pKeyContainer->dwEnumContainersCtr++;
3814 return TRUE;
3815
3817 default:
3820 return FALSE;
3821 }
3822
3823 case PP_ENUMALGS:
3824 case PP_ENUMALGS_EX:
3825 if (((pKeyContainer->dwEnumAlgsCtr >= RSAENH_MAX_ENUMALGS-1) ||
3826 (!aProvEnumAlgsEx[pKeyContainer->dwPersonality]
3827 [pKeyContainer->dwEnumAlgsCtr+1].aiAlgid)) &&
3829 {
3831 return FALSE;
3832 }
3833
3834 if (dwParam == PP_ENUMALGS) {
3835 if (pbData && (*pdwDataLen >= sizeof(PROV_ENUMALGS)))
3836 pKeyContainer->dwEnumAlgsCtr = ((dwFlags & CRYPT_FIRST) == CRYPT_FIRST) ?
3837 0 : pKeyContainer->dwEnumAlgsCtr+1;
3838
3839 provEnumalgs.aiAlgid = aProvEnumAlgsEx
3840 [pKeyContainer->dwPersonality][pKeyContainer->dwEnumAlgsCtr].aiAlgid;
3841 provEnumalgs.dwBitLen = aProvEnumAlgsEx
3842 [pKeyContainer->dwPersonality][pKeyContainer->dwEnumAlgsCtr].dwDefaultLen;
3843 provEnumalgs.dwNameLen = aProvEnumAlgsEx
3844 [pKeyContainer->dwPersonality][pKeyContainer->dwEnumAlgsCtr].dwNameLen;
3845 memcpy(provEnumalgs.szName, aProvEnumAlgsEx
3846 [pKeyContainer->dwPersonality][pKeyContainer->dwEnumAlgsCtr].szName,
3847 20*sizeof(CHAR));
3848
3849 return copy_param(pbData, pdwDataLen, (const BYTE*)&provEnumalgs,
3850 sizeof(PROV_ENUMALGS));
3851 } else {
3852 if (pbData && (*pdwDataLen >= sizeof(PROV_ENUMALGS_EX)))
3853 pKeyContainer->dwEnumAlgsCtr = ((dwFlags & CRYPT_FIRST) == CRYPT_FIRST) ?
3854 0 : pKeyContainer->dwEnumAlgsCtr+1;
3855
3856 return copy_param(pbData, pdwDataLen,
3857 (const BYTE*)&aProvEnumAlgsEx
3858 [pKeyContainer->dwPersonality][pKeyContainer->dwEnumAlgsCtr],
3859 sizeof(PROV_ENUMALGS_EX));
3860 }
3861
3862 case PP_CRYPT_COUNT_KEY_USE: /* Asked for by IE About dialog */
3863 return copy_param(pbData, pdwDataLen, abWTF, sizeof(abWTF));
3864
3866 {
3868 DWORD err, len, flags = (pKeyContainer->dwFlags & CRYPT_MACHINE_KEYSET);
3869
3870 if (!open_container_key(pKeyContainer->szName, flags, KEY_READ, &hKey))
3871 {
3873 return FALSE;
3874 }
3875
3878 if (err)
3879 {
3881 return FALSE;
3882 }
3883
3885 if (*pdwDataLen >= len) memcpy(pbData, sd, len);
3887 *pdwDataLen = len;
3888
3889 LocalFree(sd);
3890 return TRUE;
3891 }
3892
3893 default:
3894 /* MSDN: Unknown parameter number in dwParam */
3896 return FALSE;
3897 }
3898}
@ SE_REGISTRY_KEY
Definition: accctrl.h:163
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
LONG WINAPI RegEnumKeyExA(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2419
DWORD WINAPI GetSecurityInfo(HANDLE handle, SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo, PSID *ppsidOwner, PSID *ppsidGroup, PACL *ppDacl, PACL *ppSacl, PSECURITY_DESCRIPTOR *ppSecurityDescriptor)
Definition: misc.c:1244
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
#define RSAENH_MAX_ENUMALGS
Definition: rsaenh.c:168
GLbitfield flags
Definition: glext.h:7161
GLenum GLsizei len
Definition: glext.h:6722
static const WCHAR sd[]
Definition: suminfo.c:286
#define err(...)
ALG_ID aiAlgid
Definition: wincrypt.h:68
DWORD dwNameLen
Definition: wincrypt.h:63
DWORD dwBitLen
Definition: wincrypt.h:62
ALG_ID aiAlgid
Definition: wincrypt.h:61
CHAR szName[20]
Definition: wincrypt.h:64
DWORD dwEnumContainersCtr
Definition: rsaenh.c:133
DWORD WINAPI GetSecurityDescriptorLength(PSECURITY_DESCRIPTOR)
#define PP_KEYSET_SEC_DESCR
Definition: wincrypt.h:2089
#define PP_KEYSTORAGE
Definition: wincrypt.h:2097
#define PROV_RSA_FULL
Definition: wincrypt.h:2039
#define PP_ENUMALGS_EX
Definition: wincrypt.h:2101
#define PP_KEYSET_TYPE
Definition: wincrypt.h:2105
#define PP_KEYSPEC
Definition: wincrypt.h:2114
#define PP_ENUMCONTAINERS
Definition: wincrypt.h:2083
#define PP_ENUMALGS
Definition: wincrypt.h:2082
#define PP_VERSION
Definition: wincrypt.h:2086
#define CRYPT_FIRST
Definition: wincrypt.h:2060
#define PP_UNIQUE_CONTAINER
Definition: wincrypt.h:2111
#define PP_NAME
Definition: wincrypt.h:2085
#define PP_SIG_KEYSIZE_INC
Definition: wincrypt.h:2109
#define PP_KEYX_KEYSIZE_INC
Definition: wincrypt.h:2110
#define CRYPT_SEC_DESCR
Definition: wincrypt.h:2123
#define PP_IMPTYPE
Definition: wincrypt.h:2084
#define PP_CONTAINER
Definition: wincrypt.h:2087
#define PP_PROVTYPE
Definition: wincrypt.h:2096
#define CRYPT_IMPL_SOFTWARE
Definition: wincrypt.h:2064
#define PP_CRYPT_COUNT_KEY_USE
Definition: wincrypt.h:2116
char * LPSTR
Definition: xmlstorage.h:182

◆ RSAENH_CPGetUserKey()

BOOL WINAPI RSAENH_CPGetUserKey ( HCRYPTPROV  hProv,
DWORD  dwKeySpec,
HCRYPTKEY phUserKey 
)

Definition at line 4106 of file rsaenh.c.

4107{
4108 KEYCONTAINER *pKeyContainer;
4109
4110 TRACE("(hProv=%08lx, dwKeySpec=%08x, phUserKey=%p)\n", hProv, dwKeySpec, phUserKey);
4111
4112 if (!(pKeyContainer = get_key_container(hProv)))
4113 {
4114 /* MSDN: hProv not containing valid context handle */
4115 return FALSE;
4116 }
4117
4118 switch (dwKeySpec)
4119 {
4120 case AT_KEYEXCHANGE:
4122 phUserKey);
4123 break;
4124
4125 case AT_SIGNATURE:
4127 phUserKey);
4128 break;
4129
4130 default:
4131 *phUserKey = (HCRYPTKEY)INVALID_HANDLE_VALUE;
4132 }
4133
4134 if (*phUserKey == (HCRYPTKEY)INVALID_HANDLE_VALUE)
4135 {
4136 /* MSDN: dwKeySpec parameter specifies nonexistent key */
4138 return FALSE;
4139 }
4140
4141 return TRUE;
4142}
#define NTE_NO_KEY
Definition: winerror.h:2881

Referenced by RSAENH_CPSignHash().

◆ RSAENH_CPHashData()

BOOL WINAPI RSAENH_CPHashData ( HCRYPTPROV  hProv,
HCRYPTHASH  hHash,
const BYTE pbData,
DWORD  dwDataLen,
DWORD  dwFlags 
)

Definition at line 4164 of file rsaenh.c.

4166{
4167 CRYPTHASH *pCryptHash;
4168
4169 TRACE("(hProv=%08lx, hHash=%08lx, pbData=%p, dwDataLen=%d, dwFlags=%08x)\n",
4170 hProv, hHash, pbData, dwDataLen, dwFlags);
4171
4172 if (dwFlags & ~CRYPT_USERDATA)
4173 {
4175 return FALSE;
4176 }
4177
4179 (OBJECTHDR**)&pCryptHash))
4180 {
4182 return FALSE;
4183 }
4184
4185 if (!get_algid_info(hProv, pCryptHash->aiAlgid) || pCryptHash->aiAlgid == CALG_SSL3_SHAMD5)
4186 {
4188 return FALSE;
4189 }
4190
4191 if (pCryptHash->dwState != RSAENH_HASHSTATE_HASHING)
4192 {
4194 return FALSE;
4195 }
4196
4197 update_hash(pCryptHash, pbData, dwDataLen);
4198 return TRUE;
4199}
#define CRYPT_USERDATA
Definition: wincrypt.h:4140
#define NTE_BAD_HASH_STATE
Definition: winerror.h:2880

Referenced by RSAENH_CPDecrypt(), RSAENH_CPEncrypt(), RSAENH_CPHashSessionKey(), RSAENH_CPSetHashParam(), RSAENH_CPSignHash(), and RSAENH_CPVerifySignature().

◆ RSAENH_CPHashSessionKey()

BOOL WINAPI RSAENH_CPHashSessionKey ( HCRYPTPROV  hProv,
HCRYPTHASH  hHash,
HCRYPTKEY  hKey,
DWORD  dwFlags 
)

Definition at line 4216 of file rsaenh.c.

4218{
4219 BYTE abKeyValue[RSAENH_MAX_KEY_SIZE], bTemp;
4220 CRYPTKEY *pKey;
4221 DWORD i;
4222
4223 TRACE("(hProv=%08lx, hHash=%08lx, hKey=%08lx, dwFlags=%08x)\n", hProv, hHash, hKey, dwFlags);
4224
4227 {
4229 return FALSE;
4230 }
4231
4234 return FALSE;
4235 }
4236
4237 memcpy(abKeyValue, pKey->abKeyValue, pKey->dwKeyLen);
4238 if (!(dwFlags & CRYPT_LITTLE_ENDIAN)) {
4239 for (i=0; i<pKey->dwKeyLen/2; i++) {
4240 bTemp = abKeyValue[i];
4241 abKeyValue[i] = abKeyValue[pKey->dwKeyLen-i-1];
4242 abKeyValue[pKey->dwKeyLen-i-1] = bTemp;
4243 }
4244 }
4245
4246 return RSAENH_CPHashData(hProv, hHash, abKeyValue, pKey->dwKeyLen, 0);
4247}
#define CRYPT_LITTLE_ENDIAN
Definition: wincrypt.h:2221

◆ RSAENH_CPImportKey()

BOOL WINAPI RSAENH_CPImportKey ( HCRYPTPROV  hProv,
const BYTE pbData,
DWORD  dwDataLen,
HCRYPTKEY  hPubKey,
DWORD  dwFlags,
HCRYPTKEY phKey 
)

Definition at line 3132 of file rsaenh.c.

3134{
3135 TRACE("(hProv=%08lx, pbData=%p, dwDataLen=%d, hPubKey=%08lx, dwFlags=%08x, phKey=%p)\n",
3136 hProv, pbData, dwDataLen, hPubKey, dwFlags, phKey);
3137
3138 return import_key(hProv, pbData, dwDataLen, hPubKey, dwFlags, TRUE, phKey);
3139}

◆ RSAENH_CPReleaseContext()

BOOL WINAPI RSAENH_CPReleaseContext ( HCRYPTPROV  hProv,
DWORD  dwFlags 
)

Definition at line 4262 of file rsaenh.c.

4263{
4264 TRACE("(hProv=%08lx, dwFlags=%08x)\n", hProv, dwFlags);
4265
4267 {
4268 /* MSDN: hProv not containing valid context handle */
4270 return FALSE;
4271 }
4272
4273 if (dwFlags) {
4275 return FALSE;
4276 }
4277
4278 return TRUE;
4279}

◆ RSAENH_CPSetHashParam()

BOOL WINAPI RSAENH_CPSetHashParam ( HCRYPTPROV  hProv,
HCRYPTHASH  hHash,
DWORD  dwParam,
BYTE pbData,
DWORD  dwFlags 
)

Definition at line 4302 of file rsaenh.c.

4304{
4305 CRYPTHASH *pCryptHash;
4306 CRYPTKEY *pCryptKey;
4307 DWORD i;
4308
4309 TRACE("(hProv=%08lx, hHash=%08lx, dwParam=%08x, pbData=%p, dwFlags=%08x)\n",
4310 hProv, hHash, dwParam, pbData, dwFlags);
4311
4313 {
4315 return FALSE;
4316 }
4317
4318 if (dwFlags) {
4320 return FALSE;
4321 }
4322
4324 (OBJECTHDR**)&pCryptHash))
4325 {
4327 return FALSE;
4328 }
4329
4330 switch (dwParam) {
4331 case HP_HMAC_INFO:
4332 free_hmac_info(pCryptHash->pHMACInfo);
4333 if (!copy_hmac_info(&pCryptHash->pHMACInfo, (PHMAC_INFO)pbData)) return FALSE;
4334
4335 if (!lookup_handle(&handle_table, pCryptHash->hKey, RSAENH_MAGIC_KEY,
4336 (OBJECTHDR**)&pCryptKey))
4337 {
4338 SetLastError(NTE_FAIL); /* FIXME: correct error code? */
4339 return FALSE;
4340 }
4341
4342 if (pCryptKey->aiAlgid == CALG_HMAC && !pCryptKey->dwKeyLen) {
4343 HCRYPTHASH hKeyHash;
4344 DWORD keyLen;
4345
4346 if (!RSAENH_CPCreateHash(hProv, ((PHMAC_INFO)pbData)->HashAlgid, 0, 0,
4347 &hKeyHash))
4348 return FALSE;
4349 if (!RSAENH_CPHashData(hProv, hKeyHash, pCryptKey->blobHmacKey.pbData,
4350 pCryptKey->blobHmacKey.cbData, 0))
4351 {
4352 RSAENH_CPDestroyHash(hProv, hKeyHash);
4353 return FALSE;
4354 }
4355 keyLen = sizeof(pCryptKey->abKeyValue);
4356 if (!RSAENH_CPGetHashParam(hProv, hKeyHash, HP_HASHVAL, pCryptKey->abKeyValue,
4357 &keyLen, 0))
4358 {
4359 RSAENH_CPDestroyHash(hProv, hKeyHash);
4360 return FALSE;
4361 }
4362 pCryptKey->dwKeyLen = keyLen;
4363 RSAENH_CPDestroyHash(hProv, hKeyHash);
4364 }
4365 for (i=0; i<RSAENH_MIN(pCryptKey->dwKeyLen,pCryptHash->pHMACInfo->cbInnerString); i++) {
4366 pCryptHash->pHMACInfo->pbInnerString[i] ^= pCryptKey->abKeyValue[i];
4367 }
4368 for (i=0; i<RSAENH_MIN(pCryptKey->dwKeyLen,pCryptHash->pHMACInfo->cbOuterString); i++) {
4369 pCryptHash->pHMACInfo->pbOuterString[i] ^= pCryptKey->abKeyValue[i];
4370 }
4371
4372 init_hash(pCryptHash);
4373 return TRUE;
4374
4375 case HP_HASHVAL:
4376 memcpy(pCryptHash->abHashValue, pbData, pCryptHash->dwHashSize);
4377 pCryptHash->dwState = RSAENH_HASHSTATE_FINISHED;
4378 return TRUE;
4379
4380 case HP_TLS1PRF_SEED:
4381 return copy_data_blob(&pCryptHash->tpPRFParams.blobSeed, (PCRYPT_DATA_BLOB)pbData);
4382
4383 case HP_TLS1PRF_LABEL:
4384 return copy_data_blob(&pCryptHash->tpPRFParams.blobLabel, (PCRYPT_DATA_BLOB)pbData);
4385
4386 default:
4388 return FALSE;
4389 }
4390}
BOOL WINAPI RSAENH_CPDestroyHash(HCRYPTPROV hProv, HCRYPTHASH hHash)
Definition: rsaenh.c:1990
BOOL WINAPI RSAENH_CPCreateHash(HCRYPTPROV hProv, ALG_ID Algid, HCRYPTKEY hKey, DWORD dwFlags, HCRYPTHASH *phHash)
Definition: rsaenh.c:1868
#define HP_TLS1PRF_SEED
Definition: wincrypt.h:2187
#define HP_TLS1PRF_LABEL
Definition: wincrypt.h:2186
#define HP_HMAC_INFO
Definition: wincrypt.h:2185

Referenced by tls1_prf().

◆ RSAENH_CPSetKeyParam()

BOOL WINAPI RSAENH_CPSetKeyParam ( HCRYPTPROV  hProv,
HCRYPTKEY  hKey,
DWORD  dwParam,
BYTE pbData,
DWORD  dwFlags 
)

Definition at line 3384 of file rsaenh.c.

3386{
3387 CRYPTKEY *pCryptKey;
3388
3389 TRACE("(hProv=%08lx, hKey=%08lx, dwParam=%08x, pbData=%p, dwFlags=%08x)\n", hProv, hKey,
3390 dwParam, pbData, dwFlags);
3391
3393 {
3395 return FALSE;
3396 }
3397
3398 if (dwFlags) {
3400 return FALSE;
3401 }
3402
3404 {
3406 return FALSE;
3407 }
3408
3409 switch (dwParam) {
3410 case KP_PADDING:
3411 /* The MS providers only support PKCS5_PADDING */
3412 if (*(DWORD *)pbData != PKCS5_PADDING) {
3414 return FALSE;
3415 }
3416 return TRUE;
3417
3418 case KP_MODE:
3419 pCryptKey->dwMode = *(DWORD*)pbData;
3420 return TRUE;
3421
3422 case KP_MODE_BITS:
3423 pCryptKey->dwModeBits = *(DWORD*)pbData;
3424 return TRUE;
3425
3426 case KP_PERMISSIONS:
3427 {
3428 DWORD perms = *(DWORD *)pbData;
3429
3430 if ((perms & CRYPT_EXPORT) &&
3431 !(pCryptKey->dwPermissions & CRYPT_EXPORT))
3432 {
3434 return FALSE;
3435 }
3436 else if (!(perms & CRYPT_EXPORT) &&
3437 (pCryptKey->dwPermissions & CRYPT_EXPORT))
3438 {
3439 /* Clearing the export permission appears to be ignored,
3440 * see tests.
3441 */
3442 perms |= CRYPT_EXPORT;
3443 }
3444 pCryptKey->dwPermissions = perms;
3445 return TRUE;
3446 }
3447
3448 case KP_IV:
3449 memcpy(pCryptKey->abInitVector, pbData, pCryptKey->dwBlockLen);
3450 setup_key(pCryptKey);
3451 return TRUE;
3452
3453