ReactOS  0.4.14-dev-554-g2f8d847
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 CALG_SSL3_SHAMD5
Definition: wincrypt.h:1809
#define TRUE
Definition: types.h:120
unsigned int ALG_ID
Definition: wincrypt.h:45
#define CALG_SHA_384
Definition: wincrypt.h:1814
#define NTE_BAD_ALGID
Definition: winerror.h:2876
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
#define CALG_MD2
Definition: wincrypt.h:1803
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
unsigned long DWORD
Definition: ntddk_ex.h:95
#define CALG_SHA_256
Definition: wincrypt.h:1813
#define SetLastError(x)
Definition: compat.h:417
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
unsigned char BYTE
Definition: mem.h:68
#define CALG_MD5
Definition: wincrypt.h:1805
#define CALG_MD4
Definition: wincrypt.h:1804
#define CALG_SHA_512
Definition: wincrypt.h:1815
#define CRYPT_NOHASHOID
Definition: wincrypt.h:2177
#define CALG_SHA
Definition: wincrypt.h:1806
#define CRYPT_X931_FORMAT
Definition: wincrypt.h:2179

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 NTE_NO_MEMORY
Definition: winerror.h:2882
#define TRUE
Definition: types.h:120
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define SetLastError(x)
Definition: compat.h:417
BYTE * pbData
Definition: wincrypt.h:103
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLenum dst
Definition: glext.h:6340

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 }
#define NTE_NO_MEMORY
Definition: winerror.h:2882
#define TRUE
Definition: types.h:120
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define SetLastError(x)
Definition: compat.h:417
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
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 RSAENH_HMAC_DEF_PAD_LEN
Definition: rsaenh.c:147
#define TRUE
Definition: types.h:120
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum src
Definition: glext.h:6340
static void free_hmac_info(PHMAC_INFO hmac_info)
Definition: rsaenh.c:550
#define RSAENH_HMAC_DEF_OPAD_CHAR
Definition: rsaenh.c:146
GLenum GLenum dst
Definition: glext.h:6340
#define RSAENH_HMAC_DEF_IPAD_CHAR
Definition: rsaenh.c:145
#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 TRUE
Definition: types.h:120
#define SetLastError(x)
Definition: compat.h:417
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#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,
1118  REG_OPTION_NON_VOLATILE, sam, NULL, phKey, NULL)
1119  == ERROR_SUCCESS;
1120 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HKEY_CURRENT_USER
Definition: winreg.h:11
char CHAR
Definition: xmlstorage.h:175
smooth NULL
Definition: ftsmooth.c:416
#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
#define MAX_PATH
Definition: compat.h:26
#define CRYPT_MACHINE_KEYSET
Definition: wincrypt.h:2072
DWORD dwFlags
Definition: rsaenh.c:130
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:1029
CHAR szName[MAX_PATH]
Definition: rsaenh.c:134
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

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 
2627  if (dwFlags & CRYPT_SSL2_FALLBACK) {
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:
2645  if (is_valid_handle(&handle_table, hPubKey, RSAENH_MAGIC_KEY)) {
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 }
#define NTE_BAD_KEY
Definition: winerror.h:2871
static BOOL crypt_export_simple(CRYPTKEY *pCryptKey, CRYPTKEY *pPubKey, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen)
Definition: rsaenh.c:2457
#define CRYPT_SSL2_FALLBACK
Definition: wincrypt.h:2216
#define PUBLICKEYBLOB
Definition: wincrypt.h:2240
#define NTE_BAD_PUBLIC_KEY
Definition: winerror.h:2889
#define CALG_SSL2_MASTER
Definition: wincrypt.h:1848
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE _Inout_ DWORD * pdwDataLen
Definition: wincrypt.h:4201
static BOOL crypt_export_public_key(CRYPTKEY *pCryptKey, BYTE *pbData, DWORD *pdwDataLen)
Definition: rsaenh.c:2497
#define SIMPLEBLOB
Definition: wincrypt.h:2239
BOOL is_valid_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType)
Definition: handle.c:96
static BOOL crypt_export_plaintext_key(CRYPTKEY *pCryptKey, BYTE *pbData, DWORD *pdwDataLen)
Definition: rsaenh.c:2573
#define SetLastError(x)
Definition: compat.h:417
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:82
static BOOL crypt_export_private_key(CRYPTKEY *pCryptKey, BOOL force, BYTE *pbData, DWORD *pdwDataLen)
Definition: rsaenh.c:2532
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
unsigned char BYTE
Definition: mem.h:68
ALG_ID aiAlgid
Definition: rsaenh.c:99
#define NTE_BAD_TYPE
Definition: winerror.h:2878
#define PLAINTEXTKEYBLOB
Definition: wincrypt.h:2242
#define PRIVATEKEYBLOB
Definition: wincrypt.h:2241
BOOL lookup_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType, OBJECTHDR **lplpObject)
Definition: handle.c:275
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201

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 }
#define TRUE
Definition: types.h:120
ALG_ID aiKeyAlg
Definition: wincrypt.h:139
DWORD dwKeyLen
Definition: rsaenh.c:104
struct _PUBLICKEYSTRUC BLOBHEADER
BYTE abKeyValue[RSAENH_MAX_KEY_SIZE]
Definition: rsaenh.c:110
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE _Inout_ DWORD * pdwDataLen
Definition: wincrypt.h:4201
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
#define ERROR_MORE_DATA
Definition: dderror.h:13
ALG_ID aiAlgid
Definition: rsaenh.c:99
#define PLAINTEXTKEYBLOB
Definition: wincrypt.h:2242
#define CUR_BLOB_VERSION
Definition: wincrypt.h:2247
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201

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 TRUE
Definition: types.h:120
#define NTE_BAD_KEY
Definition: winerror.h:2871
ALG_ID aiKeyAlg
Definition: wincrypt.h:139
DWORD dwKeyLen
Definition: rsaenh.c:104
#define CALG_RSA_SIGN
Definition: wincrypt.h:1816
DWORD magic
Definition: wincrypt.h:143
struct _PUBLICKEYSTRUC BLOBHEADER
#define CALG_RSA_KEYX
Definition: wincrypt.h:1824
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE _Inout_ DWORD * pdwDataLen
Definition: wincrypt.h:4201
DWORD dwPermissions
Definition: rsaenh.c:103
DWORD pubexp
Definition: wincrypt.h:145
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
unsigned char BYTE
Definition: mem.h:68
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define CRYPT_EXPORT
Definition: wincrypt.h:2197
ALG_ID aiAlgid
Definition: rsaenh.c:99
DWORD bitlen
Definition: wincrypt.h:144
#define NTE_BAD_KEY_STATE
Definition: winerror.h:2879
#define CUR_BLOB_VERSION
Definition: wincrypt.h:2247
#define PRIVATEKEYBLOB
Definition: wincrypt.h:2241
#define RSAENH_MAGIC_RSA2
Definition: rsaenh.c:155
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201
KEY_CONTEXT context
Definition: rsaenh.c:109
BOOL export_private_key_impl(BYTE *pbDest, const KEY_CONTEXT *pKeyContext, DWORD dwKeyLen, DWORD *pdwPubExp)
Definition: implglue.c:438

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 TRUE
Definition: types.h:120
BOOL export_public_key_impl(BYTE *pbDest, const KEY_CONTEXT *pKeyContext, DWORD dwKeyLen, DWORD *pdwPubExp)
Definition: implglue.c:401
#define NTE_BAD_KEY
Definition: winerror.h:2871
ALG_ID aiKeyAlg
Definition: wincrypt.h:139
DWORD dwKeyLen
Definition: rsaenh.c:104
#define CALG_RSA_SIGN
Definition: wincrypt.h:1816
#define PUBLICKEYBLOB
Definition: wincrypt.h:2240
DWORD magic
Definition: wincrypt.h:143
struct _PUBLICKEYSTRUC BLOBHEADER
#define RSAENH_MAGIC_RSA1
Definition: rsaenh.c:156
#define CALG_RSA_KEYX
Definition: wincrypt.h:1824
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE _Inout_ DWORD * pdwDataLen
Definition: wincrypt.h:4201
DWORD pubexp
Definition: wincrypt.h:145
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
unsigned char BYTE
Definition: mem.h:68
#define ERROR_MORE_DATA
Definition: dderror.h:13
ALG_ID aiAlgid
Definition: rsaenh.c:99
DWORD bitlen
Definition: wincrypt.h:144
#define CUR_BLOB_VERSION
Definition: wincrypt.h:2247
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201
KEY_CONTEXT context
Definition: rsaenh.c:109

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 }
#define TRUE
Definition: types.h:120
unsigned int ALG_ID
Definition: wincrypt.h:45
#define NTE_BAD_KEY
Definition: winerror.h:2871
#define ALG_CLASS_MSG_ENCRYPT
Definition: wincrypt.h:1716
ALG_ID aiKeyAlg
Definition: wincrypt.h:139
DWORD dwKeyLen
Definition: rsaenh.c:104
struct _PUBLICKEYSTRUC BLOBHEADER
DWORD dwBlockLen
Definition: rsaenh.c:107
BYTE abKeyValue[RSAENH_MAX_KEY_SIZE]
Definition: rsaenh.c:110
#define RSAENH_ENCRYPT
Definition: rsaenh.c:143
#define GET_ALG_CLASS(x)
Definition: wincrypt.h:1709
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE _Inout_ DWORD * pdwDataLen
Definition: wincrypt.h:4201
#define ALG_CLASS_DATA_ENCRYPT
Definition: wincrypt.h:1717
#define SIMPLEBLOB
Definition: wincrypt.h:2239
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL encrypt_block_impl(ALG_ID aiAlgid, DWORD dwKeySpec, KEY_CONTEXT *pKeyContext, const BYTE *in, BYTE *out, DWORD enc)
Definition: implglue.c:303
#define SetLastError(x)
Definition: compat.h:417
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
unsigned char BYTE
Definition: mem.h:68
static BOOL pad_data(const BYTE *abData, DWORD dwDataLen, BYTE *abBuffer, DWORD dwBufferLen, DWORD dwFlags)
Definition: rsaenh.c:1693
#define ERROR_MORE_DATA
Definition: dderror.h:13
ALG_ID aiAlgid
Definition: rsaenh.c:99
#define PK_PUBLIC
Definition: tomcrypt.h:450
#define CUR_BLOB_VERSION
Definition: wincrypt.h:2247
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201
KEY_CONTEXT context
Definition: rsaenh.c:109

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 }
#define TRUE
Definition: types.h:120
#define NTE_BAD_KEYSET_PARAM
Definition: winerror.h:2899
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HKEY_CURRENT_USER
Definition: winreg.h:11
char CHAR
Definition: xmlstorage.h:175
#define snprintf
Definition: wintirpc.h:48
#define RSAENH_REGKEY
Definition: rsaenh.c:162
#define MAX_PATH
Definition: compat.h:26
#define NTE_BAD_KEYSET
Definition: winerror.h:2890
#define SetLastError(x)
Definition: compat.h:417
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define CRYPT_MACHINE_KEYSET
Definition: wincrypt.h:2072
LONG WINAPI RegDeleteKeyA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey)
Definition: reg.c:1222
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

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);
617  free_data_blob(&pCryptHash->tpPRFParams.blobLabel);
618  free_data_blob(&pCryptHash->tpPRFParams.blobSeed);
619  HeapFree(GetProcessHeap(), 0, pCryptHash);
620 }
CRYPT_DATA_BLOB blobSeed
Definition: rsaenh.c:62
#define GetProcessHeap()
Definition: compat.h:403
PHMAC_INFO pHMACInfo
Definition: rsaenh.c:75
static void free_data_blob(PCRYPT_DATA_BLOB pBlob)
Definition: rsaenh.c:527
CRYPT_DATA_BLOB blobLabel
Definition: rsaenh.c:61
static void free_hmac_info(PHMAC_INFO hmac_info)
Definition: rsaenh.c:550
RSAENH_TLS1PRF_PARAMS tpPRFParams
Definition: rsaenh.c:76
#define HeapFree(x, y, z)
Definition: compat.h:402

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 }
RSAENH_SCHANNEL_INFO siSChannelInfo
Definition: rsaenh.c:113
BOOL free_key_impl(ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext)
Definition: implglue.c:197
#define GetProcessHeap()
Definition: compat.h:403
CRYPT_DATA_BLOB blobClientRandom
Definition: rsaenh.c:92
static void free_data_blob(PCRYPT_DATA_BLOB pBlob)
Definition: rsaenh.c:527
CRYPT_DATA_BLOB blobServerRandom
Definition: rsaenh.c:93
ALG_ID aiAlgid
Definition: rsaenh.c:99
CRYPT_DATA_BLOB blobHmacKey
Definition: rsaenh.c:114
#define HeapFree(x, y, z)
Definition: compat.h:402
KEY_CONTEXT context
Definition: rsaenh.c:109

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 store_key_container_permissions(KEYCONTAINER *pKeyContainer)
Definition: rsaenh.c:1225
static void release_key_container_keys(KEYCONTAINER *pKeyContainer)
Definition: rsaenh.c:1247
#define GetProcessHeap()
Definition: compat.h:403
static void store_key_container_keys(KEYCONTAINER *pKeyContainer)
Definition: rsaenh.c:1192
#define CRYPT_VERIFYCONTEXT
Definition: wincrypt.h:2069
DWORD dwFlags
Definition: rsaenh.c:130
#define HeapFree(x, y, z)
Definition: compat.h:402

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  {
371  case DLL_PROCESS_ATTACH:
375  break;
376 
377  case DLL_PROCESS_DETACH:
378  if (reserved) break;
380  break;
381  }
382  return TRUE;
383 }
#define TRUE
Definition: types.h:120
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
void destroy_handle_table(struct handle_table *lpTable)
Definition: handle.c:72
HINSTANCE hInstance
Definition: charmap.c:20
r reserved
Definition: btrfs.c:2865
void init_handle_table(struct handle_table *lpTable)
Definition: handle.c:53
#define DLL_PROCESS_DETACH
Definition: compat.h:119
static HINSTANCE instance
Definition: rsaenh.c:50

◆ 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
static HINSTANCE instance
Definition: rsaenh.c:50

◆ 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
static HINSTANCE instance
Definition: rsaenh.c:50

◆ 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 }
ALG_ID HashAlgid
Definition: wincrypt.h:94
HCRYPTPROV hProv
Definition: rsaenh.c:70
#define TRUE
Definition: types.h:120
DWORD cbOuterString
Definition: wincrypt.h:98
HASH_CONTEXT context
Definition: rsaenh.c:73
#define RSAENH_MAX_HASH_SIZE
Definition: rsaenh.c:56
BYTE abHashValue[RSAENH_MAX_HASH_SIZE]
Definition: rsaenh.c:74
BOOL update_hash_impl(ALG_ID aiAlgid, HASH_CONTEXT *pHashContext, const BYTE *pbData, DWORD dwDataLen)
Definition: implglue.c:90
PHMAC_INFO pHMACInfo
Definition: rsaenh.c:75
HCRYPTKEY hKey
Definition: rsaenh.c:69
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL init_hash_impl(ALG_ID aiAlgid, HASH_CONTEXT *pHashContext)
Definition: implglue.c:54
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
ALG_ID aiAlgid
Definition: rsaenh.c:68
#define CALG_HMAC
Definition: wincrypt.h:1810
#define CALG_MAC
Definition: wincrypt.h:1808
BYTE * pbOuterString
Definition: wincrypt.h:97
DWORD dwHashSize
Definition: rsaenh.c:71
BOOL WINAPI RSAENH_CPEncrypt(HCRYPTPROV hProv, HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen, DWORD dwBufLen)
Definition: rsaenh.c:2183
BOOL finalize_hash_impl(ALG_ID aiAlgid, HASH_CONTEXT *pHashContext, BYTE *pbHashValue)
Definition: implglue.c:131

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 }
#define GetProcessHeap()
Definition: compat.h:403
BYTE * pbData
Definition: wincrypt.h:103
#define HeapFree(x, y, z)
Definition: compat.h:402

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
#define GetProcessHeap()
Definition: compat.h:403
BYTE * pbOuterString
Definition: wincrypt.h:97
#define HeapFree(x, y, z)
Definition: compat.h:402

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  {
447  const PROV_ENUMALGS_EX *iterator;
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 }
#define NTE_BAD_ALGID
Definition: winerror.h:2876
static HCRYPTPROV hProv
Definition: rsaenh.c:32
DWORD dwPersonality
Definition: rsaenh.c:131
smooth NULL
Definition: ftsmooth.c:416
#define SetLastError(x)
Definition: compat.h:417
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

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 }
static HCRYPTPROV hProv
Definition: rsaenh.c:32
smooth NULL
Definition: ftsmooth.c:416
#define SetLastError(x)
Definition: compat.h:417
#define NTE_BAD_UID
Definition: winerror.h:2869
#define RSAENH_MAGIC_CONTAINER
Definition: rsaenh.c:126
BOOL lookup_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType, OBJECTHDR **lplpObject)
Definition: handle.c:275

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 }
#define NTE_BAD_DATA
Definition: winerror.h:2873
#define PUBLICKEYBLOB
Definition: wincrypt.h:2240
static HCRYPTPROV hProv
Definition: rsaenh.c:32
#define TRACE(s)
Definition: solgame.cpp:4
#define SIMPLEBLOB
Definition: wincrypt.h:2239
static BOOL import_private_key(HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags, BOOL fStoreKey, HCRYPTKEY *phKey)
Definition: rsaenh.c:2757
#define SetLastError(x)
Definition: compat.h:417
static BOOL import_plaintext_key(HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags, HCRYPTKEY *phKey)
Definition: rsaenh.c:2988
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define CRYPT_VERIFYCONTEXT
Definition: wincrypt.h:2069
static KEYCONTAINER * get_key_container(HCRYPTPROV hProv)
Definition: rsaenh.c:420
#define NTE_BAD_TYPE
Definition: winerror.h:2878
#define PLAINTEXTKEYBLOB
Definition: wincrypt.h:2242
#define CUR_BLOB_VERSION
Definition: wincrypt.h:2247
#define PRIVATEKEYBLOB
Definition: wincrypt.h:2241
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
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201

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  {
3025  *phKey = (HCRYPTKEY)INVALID_HANDLE_VALUE;
3026  return FALSE;
3027  }
3028  }
3029  setup_key(pCryptKey);
3030  if (dwFlags & CRYPT_EXPORTABLE)
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);
3040  if (dwFlags & CRYPT_EXPORTABLE)
3041  pCryptKey->dwPermissions |= CRYPT_EXPORT;
3042  }
3043  return TRUE;
3044 }
#define TRUE
Definition: types.h:120
#define CRYPT_IPSEC_HMAC_KEY
Definition: wincrypt.h:91
#define NTE_BAD_DATA
Definition: winerror.h:2873
#define RSAENH_HMAC_BLOCK_LEN
Definition: rsaenh.c:148
ALG_ID aiKeyAlg
Definition: wincrypt.h:139
DWORD dwKeyLen
Definition: rsaenh.c:104
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
static HCRYPTPROV hProv
Definition: rsaenh.c:32
static void setup_key(CRYPTKEY *pCryptKey)
Definition: rsaenh.c:768
BYTE abKeyValue[RSAENH_MAX_KEY_SIZE]
Definition: rsaenh.c:110
#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
DWORD dwPermissions
Definition: rsaenh.c:103
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:82
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
BOOL release_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType)
Definition: handle.c:230
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
#define CRYPT_EXPORT
Definition: wincrypt.h:2197
#define CALG_HMAC
Definition: wincrypt.h:1810
ULONG_PTR HCRYPTKEY
Definition: wincrypt.h:49
#define CRYPT_EXPORTABLE
Definition: wincrypt.h:2206
CRYPT_DATA_BLOB blobHmacKey
Definition: rsaenh.c:114
static DWORD DWORD
Definition: rsaenh.c:111
static HCRYPTKEY new_key(HCRYPTPROV hProv, ALG_ID aiAlgid, DWORD dwFlags, CRYPTKEY **ppCryptKey)
Definition: rsaenh.c:794
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201

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) {
2806  if (dwFlags & CRYPT_EXPORTABLE)
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 CRYPT_IPSEC_HMAC_KEY
Definition: wincrypt.h:91
#define NTE_BAD_DATA
Definition: winerror.h:2873
HCRYPTKEY hSignatureKeyPair
Definition: rsaenh.c:137
ALG_ID aiKeyAlg
Definition: wincrypt.h:139
#define CALG_RSA_SIGN
Definition: wincrypt.h:1816
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
DWORD magic
Definition: wincrypt.h:143
static HCRYPTPROV hProv
Definition: rsaenh.c:32
HCRYPTKEY hKeyExchangeKeyPair
Definition: rsaenh.c:136
#define AT_KEYEXCHANGE
Definition: wincrypt.h:2035
struct _PUBLICKEYSTRUC BLOBHEADER
static void setup_key(CRYPTKEY *pCryptKey)
Definition: rsaenh.c:768
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FIXME(fmt,...)
Definition: debug.h:110
#define MAKELONG(a, b)
Definition: typedefs.h:248
#define CALG_RSA_KEYX
Definition: wincrypt.h:1824
DWORD dwPermissions
Definition: rsaenh.c:103
#define TRACE(s)
Definition: solgame.cpp:4
DWORD pubexp
Definition: wincrypt.h:145
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
static void release_and_install_key(HCRYPTPROV hProv, HCRYPTKEY src, HCRYPTKEY *dest, DWORD fStoreKey)
Definition: rsaenh.c:2717
int ret
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
unsigned char BYTE
Definition: mem.h:68
#define CRYPT_EXPORT
Definition: wincrypt.h:2197
static KEYCONTAINER * get_key_container(HCRYPTPROV hProv)
Definition: rsaenh.c:420
#define ERR(fmt,...)
Definition: debug.h:109
DWORD bitlen
Definition: wincrypt.h:144
#define NTE_BAD_FLAGS
Definition: winerror.h:2877
ULONG_PTR HCRYPTKEY
Definition: wincrypt.h:49
#define AT_SIGNATURE
Definition: wincrypt.h:2036
#define CRYPT_EXPORTABLE
Definition: wincrypt.h:2206
BOOL import_private_key_impl(const BYTE *pbSrc, KEY_CONTEXT *pKeyContext, DWORD dwKeyLen, DWORD dwDataLen, DWORD dwPubExp)
Definition: implglue.c:487
#define RSAENH_MAGIC_RSA2
Definition: rsaenh.c:155
static HCRYPTKEY new_key(HCRYPTPROV hProv, ALG_ID aiAlgid, DWORD dwFlags, CRYPTKEY **ppCryptKey)
Definition: rsaenh.c:794
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201
KEY_CONTEXT context
Definition: rsaenh.c:109

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) {
2883  if (dwFlags & CRYPT_EXPORTABLE)
2884  pCryptKey->dwPermissions |= CRYPT_EXPORT;
2885  }
2886  return ret;
2887 }
unsigned int ALG_ID
Definition: wincrypt.h:45
#define CRYPT_IPSEC_HMAC_KEY
Definition: wincrypt.h:91
#define NTE_BAD_DATA
Definition: winerror.h:2873
ALG_ID aiKeyAlg
Definition: wincrypt.h:139
BOOL import_public_key_impl(const BYTE *pbSrc, KEY_CONTEXT *pKeyContext, DWORD dwKeyLen, DWORD dwPubExp)
Definition: implglue.c:412
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
DWORD magic
Definition: wincrypt.h:143
static HCRYPTPROV hProv
Definition: rsaenh.c:32
static void setup_key(CRYPTKEY *pCryptKey)
Definition: rsaenh.c:768
#define RSAENH_MAGIC_RSA1
Definition: rsaenh.c:156
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FIXME(fmt,...)
Definition: debug.h:110
#define MAKELONG(a, b)
Definition: typedefs.h:248
DWORD dwPermissions
Definition: rsaenh.c:103
DWORD pubexp
Definition: wincrypt.h:145
#define SetLastError(x)
Definition: compat.h:417
int ret
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
unsigned char BYTE
Definition: mem.h:68
#define CRYPT_EXPORT
Definition: wincrypt.h:2197
DWORD bitlen
Definition: wincrypt.h:144
#define NTE_BAD_FLAGS
Definition: winerror.h:2877
ULONG_PTR HCRYPTKEY
Definition: wincrypt.h:49
#define CRYPT_EXPORTABLE
Definition: wincrypt.h:2206
static HCRYPTKEY new_key(HCRYPTPROV hProv, ALG_ID aiAlgid, DWORD dwFlags, CRYPTKEY **ppCryptKey)
Definition: rsaenh.c:794
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201
KEY_CONTEXT context
Definition: rsaenh.c:109

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,
2944  RSAENH_DECRYPT);
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);
2961  if (dwFlags & CRYPT_EXPORTABLE)
2962  pCryptKey->dwPermissions |= CRYPT_EXPORT;
2963  return TRUE;
2964 }
#define TRUE
Definition: types.h:120
unsigned int ALG_ID
Definition: wincrypt.h:45
#define CRYPT_IPSEC_HMAC_KEY
Definition: wincrypt.h:91
#define NTE_BAD_DATA
Definition: winerror.h:2873
ALG_ID aiKeyAlg
Definition: wincrypt.h:139
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
#define NTE_BAD_PUBLIC_KEY
Definition: winerror.h:2889
static HCRYPTPROV hProv
Definition: rsaenh.c:32
#define RSAENH_MAX_KEY_SIZE
Definition: rsaenh.c:83
static BOOL unpad_data(const BYTE *abData, DWORD dwDataLen, BYTE *abBuffer, DWORD *dwBufferLen, DWORD dwFlags)
Definition: rsaenh.c:1734
static void setup_key(CRYPTKEY *pCryptKey)
Definition: rsaenh.c:768
#define FIXME(fmt,...)
Definition: debug.h:110
BYTE abKeyValue[RSAENH_MAX_KEY_SIZE]
Definition: rsaenh.c:110
#define CALG_RSA_KEYX
Definition: wincrypt.h:1824
#define PK_PRIVATE
Definition: tomcrypt.h:449
DWORD dwPermissions
Definition: rsaenh.c:103
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL encrypt_block_impl(ALG_ID aiAlgid, DWORD dwKeySpec, KEY_CONTEXT *pKeyContext, const BYTE *in, BYTE *out, DWORD enc)
Definition: implglue.c:303
#define SetLastError(x)
Definition: compat.h:417
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:82
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
#define CRYPT_EXPORT
Definition: wincrypt.h:2197
#define NTE_BAD_FLAGS
Definition: winerror.h:2877
ULONG_PTR HCRYPTKEY
Definition: wincrypt.h:49
#define CRYPT_EXPORTABLE
Definition: wincrypt.h:2206
#define RSAENH_DECRYPT
Definition: rsaenh.c:144
BOOL lookup_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType, OBJECTHDR **lplpObject)
Definition: handle.c:275
#define HeapFree(x, y, z)
Definition: compat.h:402
static HCRYPTKEY new_key(HCRYPTPROV hProv, ALG_ID aiAlgid, DWORD dwFlags, CRYPTKEY **ppCryptKey)
Definition: rsaenh.c:794
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201

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 }
smooth NULL
Definition: ftsmooth.c:416
BYTE * pbData
Definition: wincrypt.h:103

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 }
ALG_ID HashAlgid
Definition: wincrypt.h:94
HCRYPTPROV hProv
Definition: rsaenh.c:70
BYTE * pbInnerString
Definition: wincrypt.h:95
#define KP_BLOCKLEN
Definition: wincrypt.h:2135
#define TRUE
Definition: types.h:120
BOOL WINAPI RSAENH_CPGetKeyParam(HCRYPTPROV hProv, HCRYPTKEY hKey, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
Definition: rsaenh.c:3601
HASH_CONTEXT context
Definition: rsaenh.c:73
DWORD cbInnerString
Definition: wincrypt.h:96
BOOL update_hash_impl(ALG_ID aiAlgid, HASH_CONTEXT *pHashContext, const BYTE *pbData, DWORD dwDataLen)
Definition: implglue.c:90
PHMAC_INFO pHMACInfo
Definition: rsaenh.c:75
HCRYPTKEY hKey
Definition: rsaenh.c:69
unsigned long DWORD
Definition: ntddk_ex.h:95
static const PROV_ENUMALGS_EX * get_algid_info(HCRYPTPROV hProv, ALG_ID algid)
Definition: rsaenh.c:446
BOOL init_hash_impl(ALG_ID aiAlgid, HASH_CONTEXT *pHashContext)
Definition: implglue.c:54
unsigned char BYTE
Definition: mem.h:68
ALG_ID aiAlgid
Definition: rsaenh.c:68
#define CALG_HMAC
Definition: wincrypt.h:1810
#define CALG_MAC
Definition: wincrypt.h:1808
DWORD dwHashSize
Definition: rsaenh.c:71
DWORD dwDefaultLen
Definition: wincrypt.h:69
static DWORD DWORD
Definition: rsaenh.c:111

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:111
#define AT_KEYEXCHANGE
Definition: wincrypt.h:2035
smooth NULL
Definition: ftsmooth.c:416
const char * LPCSTR
Definition: xmlstorage.h:183
#define AT_SIGNATURE
Definition: wincrypt.h:2036

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 }
#define WARN(fmt,...)
Definition: debug.h:111
#define AT_KEYEXCHANGE
Definition: wincrypt.h:2035
smooth NULL
Definition: ftsmooth.c:416
const char * LPCSTR
Definition: xmlstorage.h:183
#define AT_SIGNATURE
Definition: wincrypt.h:2036

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) {
843  dwKeyLen = RSAENH_3DES_STORAGE_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 }
#define CALG_AES_192
Definition: wincrypt.h:1834
#define CALG_RC2
Definition: wincrypt.h:1829
#define CALG_3DES
Definition: wincrypt.h:1830
#define NTE_BAD_DATA
Definition: winerror.h:2873
#define NTE_BAD_ALGID
Definition: winerror.h:2876
#define RSAENH_3DES112_EFFECTIVE_KEYLEN
Definition: rsaenh.c:151
#define CRYPT_NO_SALT
Definition: wincrypt.h:2210
DWORD dwKeyLen
Definition: rsaenh.c:104
SCHANNEL_ALG saMACAlg
Definition: rsaenh.c:91
#define CALG_RSA_SIGN
Definition: wincrypt.h:1816
#define CALG_RC4
Definition: wincrypt.h:1837
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
#define CRYPT_ENCRYPT
Definition: wincrypt.h:2195
static void destroy_key(OBJECTHDR *pObject)
Definition: rsaenh.c:749
#define CALG_TLS1_MASTER
Definition: wincrypt.h:1849
static HCRYPTPROV hProv
Definition: rsaenh.c:32
#define CALG_3DES_112
Definition: wincrypt.h:1831
#define CRYPT_MODE_CBC
Definition: wincrypt.h:2190
#define CALG_AES_256
Definition: wincrypt.h:1835
DWORD dwBlockLen
Definition: rsaenh.c:107
#define CALG_SSL2_MASTER
Definition: wincrypt.h:1848
BYTE abKeyValue[RSAENH_MAX_KEY_SIZE]
Definition: rsaenh.c:110
RSAENH_SCHANNEL_INFO siSChannelInfo
Definition: rsaenh.c:113
DWORD dwPersonality
Definition: rsaenh.c:131
smooth NULL
Definition: ftsmooth.c:416
#define CALG_DES
Definition: wincrypt.h:1828
#define CALG_RSA_KEYX
Definition: wincrypt.h:1824
HCRYPTKEY new_object(struct handle_table *lpTable, size_t cbSize, DWORD dwType, DESTRUCTOR destructor, OBJECTHDR **ppObject)
Definition: handle.c:353
#define CRYPT_READ
Definition: wincrypt.h:2198
#define CRYPT_MAC
Definition: wincrypt.h:2200
DWORD dwPermissions
Definition: rsaenh.c:103
#define TRACE(s)
Definition: solgame.cpp:4
CRYPT_DATA_BLOB blobClientRandom
Definition: rsaenh.c:92
#define debugstr_a
Definition: kernel32.h:31
CRYPT_DATA_BLOB blobServerRandom
Definition: rsaenh.c:93
#define RSAENH_DES_STORAGE_KEYLEN
Definition: rsaenh.c:150
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
static const PROV_ENUMALGS_EX * get_algid_info(HCRYPTPROV hProv, ALG_ID algid)
Definition: rsaenh.c:446
#define CALG_SSL3_MASTER
Definition: wincrypt.h:1843
DWORD dwEffectiveKeyLen
Definition: rsaenh.c:105
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:82
#define CRYPT_DECRYPT
Definition: wincrypt.h:2196
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
CHAR szName[20]
Definition: wincrypt.h:74
#define CALG_PCT1_MASTER
Definition: wincrypt.h:1847
#define CRYPT_EXPORT
Definition: wincrypt.h:2197
#define CALG_HMAC
Definition: wincrypt.h:1810
static KEYCONTAINER * get_key_container(HCRYPTPROV hProv)
Definition: rsaenh.c:420
#define CALG_AES_128
Definition: wincrypt.h:1833
ALG_ID aiAlgid
Definition: rsaenh.c:99
DWORD dwModeBits
Definition: rsaenh.c:102
BYTE abInitVector[RSAENH_MAX_BLOCK_SIZE]
Definition: rsaenh.c:111
DWORD dwSaltLen
Definition: rsaenh.c:106
#define RSAENH_3DES112_STORAGE_KEYLEN
Definition: rsaenh.c:152
SCHANNEL_ALG saEncAlg
Definition: rsaenh.c:90
#define NTE_BAD_FLAGS
Definition: winerror.h:2877
ULONG_PTR HCRYPTKEY
Definition: wincrypt.h:49
static void init_data_blob(PCRYPT_DATA_BLOB pBlob)
Definition: rsaenh.c:534
DWORD dwMode
Definition: rsaenh.c:101
#define CALG_AES
Definition: wincrypt.h:1836
#define HIWORD(l)
Definition: typedefs.h:246
#define CRYPT_CREATE_SALT
Definition: wincrypt.h:2208
#define CRYPT_EXPORTABLE
Definition: wincrypt.h:2206
#define RSAENH_3DES_EFFECTIVE_KEYLEN
Definition: rsaenh.c:153
HCRYPTPROV hProv
Definition: rsaenh.c:100
CRYPT_DATA_BLOB blobHmacKey
Definition: rsaenh.c:114
#define memset(x, y, z)
Definition: compat.h:39
#define CRYPT_WRITE
Definition: wincrypt.h:2199
#define RSAENH_PERSONALITY_ENHANCED
Definition: rsaenh.c:122
#define RSAENH_DES_EFFECTIVE_KEYLEN
Definition: rsaenh.c:149
DWORD dwDefaultLen
Definition: wincrypt.h:69
#define RSAENH_3DES_STORAGE_KEYLEN
Definition: rsaenh.c:154

Referenced by ___w64_mingwthr_add_key_dtor(), 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 
1297  hKeyContainer = new_object(&handle_table, sizeof(KEYCONTAINER), RSAENH_MAGIC_CONTAINER,
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)) {
1311  pKeyContainer->dwPersonality = RSAENH_PERSONALITY_ENHANCED;
1312  } else if (!strcmp(pVTable->pszProvName, MS_DEF_RSA_SCHANNEL_PROV_A)) {
1313  pKeyContainer->dwPersonality = RSAENH_PERSONALITY_SCHANNEL;
1314  } else if (!strcmp(pVTable->pszProvName, MS_ENH_RSA_AES_PROV_A) ||
1316  pKeyContainer->dwPersonality = RSAENH_PERSONALITY_AES;
1317  } else {
1318  pKeyContainer->dwPersonality = RSAENH_PERSONALITY_STRONG;
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))
1328  RegCloseKey(hKey);
1329  }
1330  }
1331 
1332  return hKeyContainer;
1333 }
CHAR szProvName[MAX_PATH]
Definition: rsaenh.c:135
HCRYPTKEY hSignatureKeyPair
Definition: rsaenh.c:137
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
static BOOL create_container_key(KEYCONTAINER *pKeyContainer, REGSAM sam, HKEY *phKey)
Definition: rsaenh.c:1103
#define RSAENH_PERSONALITY_SCHANNEL
Definition: rsaenh.c:123
HCRYPTKEY hKeyExchangeKeyPair
Definition: rsaenh.c:136
#define MS_DEF_RSA_SCHANNEL_PROV_A
Definition: wincrypt.h:1916
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
LPSTR pszProvName
Definition: wincrypt.h:708
#define RSAENH_PERSONALITY_STRONG
Definition: rsaenh.c:121
#define MS_ENHANCED_PROV_A
Definition: wincrypt.h:1874
DWORD dwPersonality
Definition: rsaenh.c:131
#define RSAENH_PERSONALITY_AES
Definition: rsaenh.c:124
#define RSAENH_PERSONALITY_BASE
Definition: rsaenh.c:120
HCRYPTKEY new_object(struct handle_table *lpTable, size_t cbSize, DWORD dwType, DESTRUCTOR destructor, OBJECTHDR **ppObject)
Definition: handle.c:353
#define KEY_WRITE
Definition: nt_native.h:1031
static void destroy_key_container(OBJECTHDR *pObjectHdr)
Definition: rsaenh.c:1263
#define MAX_PATH
Definition: compat.h:26
#define MS_DEF_PROV_A
Definition: wincrypt.h:1860
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define MS_ENH_RSA_AES_PROV_A
Definition: wincrypt.h:2004
DWORD dwEnumAlgsCtr
Definition: rsaenh.c:132
#define CRYPT_VERIFYCONTEXT
Definition: wincrypt.h:2069
DWORD dwFlags
Definition: rsaenh.c:130
ULONG_PTR HCRYPTPROV
Definition: wincrypt.h:46
#define lstrcpynA
Definition: compat.h:416
ULONG_PTR HCRYPTKEY
Definition: wincrypt.h:49
#define MS_ENH_RSA_AES_PROV_XP_A
Definition: wincrypt.h:2018
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define RSAENH_MAGIC_CONTAINER
Definition: rsaenh.c:126
CHAR szName[MAX_PATH]
Definition: rsaenh.c:134
#define RSAENH_PERSONALITY_ENHANCED
Definition: rsaenh.c:122

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) ==
1149  ERROR_SUCCESS;
1150 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HKEY_CURRENT_USER
Definition: winreg.h:11
char CHAR
Definition: xmlstorage.h:175
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3331
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define RSAENH_REGKEY
Definition: rsaenh.c:162
#define MAX_PATH
Definition: compat.h:26
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define CRYPT_MACHINE_KEYSET
Definition: wincrypt.h:2072
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

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 memmove(s1, s2, n)
Definition: mkisofs.h:881
#define TRUE
Definition: types.h:120
BOOL gen_rand_impl(BYTE *pbBuffer, DWORD dwLen)
Definition: implglue.c:396
#define CRYPT_SSL2_FALLBACK
Definition: wincrypt.h:2216
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
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define NTE_BAD_LEN
Definition: winerror.h:2872
#define RSAENH_PKC_BLOCKTYPE
Definition: rsaenh.c:157

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 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
static BOOL open_container_key(LPCSTR pszContainerName, DWORD dwFlags, REGSAM access, HKEY *phKey)
Definition: rsaenh.c:1134
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
static HCRYPTPROV new_key_container(PCCH pszContainerName, DWORD dwFlags, const VTableProvStruc *pVTable)
Definition: rsaenh.c:1292
#define AT_KEYEXCHANGE
Definition: wincrypt.h:2035
#define NTE_BAD_KEYSET
Definition: winerror.h:2890
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:82
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
BOOL release_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType)
Definition: handle.c:230
#define CRYPT_MACHINE_KEYSET
Definition: wincrypt.h:2072
ULONG_PTR HCRYPTPROV
Definition: wincrypt.h:46
ULONG_PTR HCRYPTKEY
Definition: wincrypt.h:49
#define AT_SIGNATURE
Definition: wincrypt.h:2036
#define RSAENH_MAGIC_CONTAINER
Definition: rsaenh.c:126
BOOL lookup_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType, OBJECTHDR **lplpObject)
Definition: handle.c:275
#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) ==
1358  ERROR_SUCCESS)
1359  {
1360  pbKey = HeapAlloc(GetProcessHeap(), 0, dwLen);
1361  if (pbKey)
1362  {
1363  if (RegQueryValueExA(hKey, szValueName, 0, &dwValueType, pbKey, &dwLen) ==
1364  ERROR_SUCCESS)
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:4023
#define ERROR_SUCCESS
Definition: deptool.c:10
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
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
const char * LPCSTR
Definition: xmlstorage.h:183
static BOOL import_key(HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, HCRYPTKEY hPubKey, DWORD dwFlags, BOOL fStoreKey, HCRYPTKEY *phKey)
Definition: rsaenh.c:3066
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:82
int ret
BYTE * pbData
Definition: wincrypt.h:103
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
unsigned char BYTE
Definition: mem.h:68
static LPCSTR map_key_spec_to_key_pair_name(DWORD dwKeySpec)
Definition: rsaenh.c:969
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
static LPCSTR map_key_spec_to_permissions_name(DWORD dwKeySpec)
Definition: rsaenh.c:1050
BOOL lookup_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType, OBJECTHDR **lplpObject)
Definition: handle.c:275
#define HeapFree(x, y, z)
Definition: compat.h:402

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 }
static void store_key_container_permissions(KEYCONTAINER *pKeyContainer)
Definition: rsaenh.c:1225
static HCRYPTPROV hProv
Definition: rsaenh.c:32
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:82
BOOL copy_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType, HCRYPTKEY *copy)
Definition: handle.c:310
GLenum src
Definition: glext.h:6340
static void store_key_container_keys(KEYCONTAINER *pKeyContainer)
Definition: rsaenh.c:1192
static KEYCONTAINER * get_key_container(HCRYPTPROV hProv)
Definition: rsaenh.c:420
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 }
HCRYPTKEY hSignatureKeyPair
Definition: rsaenh.c:137
HCRYPTKEY hKeyExchangeKeyPair
Definition: rsaenh.c:136
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:82
BOOL release_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType)
Definition: handle.c:230

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 
1825  case CRYPT_VERIFYCONTEXT:
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:
1835  *phProv = (HCRYPTPROV)INVALID_HANDLE_VALUE;
1837  return FALSE;
1838  }
1839 
1840  if (*phProv != (HCRYPTPROV)INVALID_HANDLE_VALUE) {
1842  return TRUE;
1843  } else {
1844  return FALSE;
1845  }
1846 }
#define CRYPT_NEWKEYSET
Definition: wincrypt.h:2070
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
static HCRYPTPROV read_key_container(PCHAR pszContainerName, DWORD dwFlags, const VTableProvStruc *pVTable)
Definition: rsaenh.c:1412
char CHAR
Definition: xmlstorage.h:175
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
static HCRYPTPROV new_key_container(PCCH pszContainerName, DWORD dwFlags, const VTableProvStruc *pVTable)
Definition: rsaenh.c:1292
#define TRACE(s)
Definition: solgame.cpp:4
#define NTE_EXISTS
Definition: winerror.h:2883
#define debugstr_a
Definition: kernel32.h:31
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
BOOL release_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType)
Definition: handle.c:230
BOOL WINAPI GetUserNameA(LPSTR lpszName, LPDWORD lpSize)
Definition: misc.c:246
#define CRYPT_VERIFYCONTEXT
Definition: wincrypt.h:2069
static BOOL delete_container_key(LPCSTR pszContainerName, DWORD dwFlags)
Definition: rsaenh.c:1161
ULONG_PTR HCRYPTPROV
Definition: wincrypt.h:46
#define NTE_BAD_FLAGS
Definition: winerror.h:2877
#define lstrcpynA
Definition: compat.h:416
#define CRYPT_DELETEKEYSET
Definition: wincrypt.h:2071
#define RSAENH_MAGIC_CONTAINER
Definition: rsaenh.c:126

◆ 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 
1920  *phHash = new_object(&handle_table, sizeof(CRYPTHASH), RSAENH_MAGIC_HASH,
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 GET_ALG_TYPE(x)
Definition: wincrypt.h:1710
#define CALG_SCHANNEL_MASTER_HASH
Definition: wincrypt.h:1844
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
HCRYPTPROV hProv
Definition: rsaenh.c:70
static BOOL concat_data_blobs(PCRYPT_DATA_BLOB dst, const PCRYPT_DATA_BLOB src1, const PCRYPT_DATA_BLOB src2)
Definition: rsaenh.c:505
#define NTE_BAD_KEY
Definition: winerror.h:2871
#define RSAENH_MAX_HASH_SIZE
Definition: rsaenh.c:56
CRYPT_DATA_BLOB blobSeed
Definition: rsaenh.c:62
#define RSAENH_HASHSTATE_HASHING
Definition: rsaenh.c:57
#define CALG_TLS1_MASTER
Definition: wincrypt.h:1849
static HCRYPTPROV hProv
Definition: rsaenh.c:32
static void destroy_hash(OBJECTHDR *pObject)
Definition: rsaenh.c:612
DWORD dwState
Definition: rsaenh.c:72
BYTE abHashValue[RSAENH_MAX_HASH_SIZE]
Definition: rsaenh.c:74
#define CALG_TLS1PRF
Definition: wincrypt.h:1811
smooth NULL
Definition: ftsmooth.c:416
HCRYPTKEY new_object(struct handle_table *lpTable, size_t cbSize, DWORD dwType, DESTRUCTOR destructor, OBJECTHDR **ppObject)
Definition: handle.c:353
#define RSAENH_KEYSTATE_MASTERKEY
Definition: rsaenh.c:87
#define TRACE(s)
Definition: solgame.cpp:4
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
PHMAC_INFO pHMACInfo
Definition: rsaenh.c:75
HCRYPTKEY hKey
Definition: rsaenh.c:69
static void free_data_blob(PCRYPT_DATA_BLOB pBlob)
Definition: rsaenh.c:527
#define SetLastError(x)
Definition: compat.h:417
static const PROV_ENUMALGS_EX * get_algid_info(HCRYPTPROV hProv, ALG_ID algid)
Definition: rsaenh.c:446
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:82
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
ALG_ID aiAlgid
Definition: rsaenh.c:68
CRYPT_DATA_BLOB blobLabel
Definition: rsaenh.c:61
#define CALG_HMAC
Definition: wincrypt.h:1810
static BOOL init_hash(CRYPTHASH *pCryptHash)
Definition: rsaenh.c:630
#define CALG_MAC
Definition: wincrypt.h:1808
RSAENH_TLS1PRF_PARAMS tpPRFParams
Definition: rsaenh.c:76
DWORD dwHashSize
Definition: rsaenh.c:71
#define NTE_BAD_FLAGS
Definition: winerror.h:2877
#define RSAENH_MAGIC_HASH
Definition: rsaenh.c:55
#define NTE_BAD_KEY_STATE
Definition: winerror.h:2879
static void init_data_blob(PCRYPT_DATA_BLOB pBlob)
Definition: rsaenh.c:534
BOOL lookup_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType, OBJECTHDR **lplpObject)
Definition: handle.c:275
#define ALG_TYPE_BLOCK
Definition: wincrypt.h:1725
DWORD dwDefaultLen
Definition: wincrypt.h:69

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 
2358  if (!lookup_handle(&handle_table, hKey, RSAENH_MAGIC_KEY, (OBJECTHDR**)&pCryptKey))
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,
2380  RSAENH_DECRYPT);
2381  break;
2382 
2383  case CRYPT_MODE_CBC:
2384  encrypt_block_impl(pCryptKey->aiAlgid, 0, &pCryptKey->context, in, out,
2385  RSAENH_DECRYPT);
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)
2418  *pdwDataLen -= pbData[*pdwDataLen-1];
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 GET_ALG_TYPE(x)
Definition: wincrypt.h:1710
#define TRUE
Definition: types.h:120
_In_ HCRYPTHASH hHash
Definition: wincrypt.h:4198
#define NTE_BAD_DATA
Definition: winerror.h:2873
#define NTE_BAD_KEY
Definition: winerror.h:2871
BOOL WINAPI RSAENH_CPHashData(HCRYPTPROV hProv, HCRYPTHASH hHash, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
Definition: rsaenh.c:4164
#define NTE_BAD_ALGID
Definition: winerror.h:2876
#define CALG_RSA_SIGN
Definition: wincrypt.h:1816
static HCRYPTPROV hProv
Definition: rsaenh.c:32
#define ALG_TYPE_STREAM
Definition: wincrypt.h:1726
static BOOL unpad_data(const BYTE *abData, DWORD dwDataLen, BYTE *abBuffer, DWORD *dwBufferLen, DWORD dwFlags)
Definition: rsaenh.c:1734
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
#define CRYPT_MODE_CBC
Definition: wincrypt.h:2190
static void setup_key(CRYPTKEY *pCryptKey)
Definition: rsaenh.c:768
unsigned int BOOL
Definition: ntddk_ex.h:94
#define RSAENH_ENCRYPT
Definition: rsaenh.c:143
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE _Inout_ DWORD * pdwDataLen
Definition: wincrypt.h:4201
#define PK_PRIVATE
Definition: tomcrypt.h:449
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 ALG_TYPE_RSA
Definition: wincrypt.h:1724
#define CRYPT_MODE_CFB
Definition: wincrypt.h:2193
#define TRACE(s)
Definition: solgame.cpp:4
BOOL is_valid_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType)
Definition: handle.c:96
_In_ HCRYPTHASH _In_ BOOL Final
Definition: wincrypt.h:4198
#define RSAENH_KEYSTATE_ENCRYPTING
Definition: rsaenh.c:86
static FILE * out
Definition: regtests2xml.c:44
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL encrypt_block_impl(ALG_ID aiAlgid, DWORD dwKeySpec, KEY_CONTEXT *pKeyContext, const BYTE *in, BYTE *out, DWORD enc)
Definition: implglue.c:303
#define SetLastError(x)
Definition: compat.h:417
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:82
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
#define RSAENH_KEYSTATE_IDLE
Definition: rsaenh.c:85
BOOL encrypt_stream_impl(ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext, BYTE *stream, DWORD dwLen)
Definition: implglue.c:381
GLuint in
Definition: glext.h:9616
#define NTE_BAD_TYPE
Definition: winerror.h:2878
#define NTE_BAD_FLAGS
Definition: winerror.h:2877
#define RSAENH_MAGIC_HASH
Definition: rsaenh.c:55
#define RSAENH_MAX_BLOCK_SIZE
Definition: rsaenh.c:84
#define NTE_BAD_UID
Definition: winerror.h:2869
#define RSAENH_MAGIC_CONTAINER
Definition: rsaenh.c:126
#define RSAENH_DECRYPT
Definition: rsaenh.c:144
BOOL lookup_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType, OBJECTHDR **lplpObject)
Definition: handle.c:275
#define ALG_TYPE_BLOCK
Definition: wincrypt.h:1725
int k
Definition: mpi.c:3369
#define CRYPT_MODE_ECB
Definition: wincrypt.h:2191
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201

◆ 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 
3939  if (!lookup_handle(&handle_table, hBaseData, RSAENH_MAGIC_HASH,
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  }
4027  case ALG_CLASS_MSG_ENCRYPT:
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 */
4038  case CALG_SCHANNEL_ENC_KEY:
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 
4063  case CALG_SCHANNEL_MAC_KEY:
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 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define NTE_BAD_HASH
Definition: winerror.h:2870
#define RSAENH_HMAC_DEF_PAD_LEN
Definition: rsaenh.c:147
#define CALG_RC2
Definition: wincrypt.h:1829
#define TRUE
Definition: types.h:120
#define RSAENH_MAX_HASH_SIZE
Definition: rsaenh.c:56
#define ALG_CLASS_MSG_ENCRYPT
Definition: wincrypt.h:1716
#define NTE_BAD_ALGID
Definition: winerror.h:2876
DWORD dwKeyLen
Definition: rsaenh.c:104
#define CALG_RC4
Definition: wincrypt.h:1837
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
static HCRYPTPROV hProv
Definition: rsaenh.c:32
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
#define CALG_SCHANNEL_ENC_KEY
Definition: wincrypt.h:1846
#define NTE_FAIL
Definition: winerror.h:2900
static void setup_key(CRYPTKEY *pCryptKey)
Definition: rsaenh.c:768
static void finalize_hash(CRYPTHASH *pCryptHash)
Definition: rsaenh.c:706
DWORD dwBlockLen
Definition: rsaenh.c:107
BYTE abKeyValue[RSAENH_MAX_KEY_SIZE]
Definition: rsaenh.c:110
#define RSAENH_MIN(a, b)
Definition: rsaenh.c:164
#define MAKELONG(a, b)
Definition: typedefs.h:248
#define GET_ALG_CLASS(x)
Definition: wincrypt.h:1709
#define ALG_CLASS_DATA_ENCRYPT
Definition: wincrypt.h:1717
#define TRACE(s)
Definition: solgame.cpp:4
BOOL is_valid_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType)
Definition: handle.c:96
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:82
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
static BOOL init_hash(CRYPTHASH *pCryptHash)
Definition: rsaenh.c:630
BOOL WINAPI RSAENH_CPGetHashParam(HCRYPTPROV hProv, HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
Definition: rsaenh.c:3291
#define CALG_AES_128
Definition: wincrypt.h:1833
BYTE abInitVector[RSAENH_MAX_BLOCK_SIZE]
Definition: rsaenh.c:111
#define CALG_SCHANNEL_MAC_KEY
Definition: wincrypt.h:1845
DWORD dwSaltLen
Definition: rsaenh.c:106
static void update_hash(CRYPTHASH *pCryptHash, const BYTE *pbData, DWORD dwDataLen)
Definition: rsaenh.c:671
#define RSAENH_HMAC_DEF_OPAD_CHAR
Definition: rsaenh.c:146
#define NTE_BAD_FLAGS
Definition: winerror.h:2877
ULONG_PTR HCRYPTKEY
Definition: wincrypt.h:49
#define RSAENH_MAGIC_HASH
Definition: rsaenh.c:55
#define NTE_BAD_UID
Definition: winerror.h:2869
#define CRYPT_CREATE_SALT
Definition: wincrypt.h:2208
#define RSAENH_MAGIC_CONTAINER
Definition: rsaenh.c:126
#define RSAENH_HMAC_DEF_IPAD_CHAR
Definition: rsaenh.c:145
#define CRYPT_SERVER
Definition: wincrypt.h:2212
BOOL lookup_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType, OBJECTHDR **lplpObject)
Definition: handle.c:275
#define HP_HASHVAL
Definition: wincrypt.h:2183
#define LOWORD(l)
Definition: pedump.c:82
static HCRYPTKEY new_key(HCRYPTPROV hProv, ALG_ID aiAlgid, DWORD dwFlags, CRYPTKEY **ppCryptKey)
Definition: rsaenh.c:794

◆ 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 }
#define NTE_BAD_HASH
Definition: winerror.h:2870
#define TRUE
Definition: types.h:120
_In_ HCRYPTHASH hHash
Definition: wincrypt.h:4198
static HCRYPTPROV hProv
Definition: rsaenh.c:32
#define TRACE(s)
Definition: solgame.cpp:4
BOOL is_valid_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType)
Definition: handle.c:96
#define SetLastError(x)
Definition: compat.h:417
BOOL release_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType)
Definition: handle.c:230
#define RSAENH_MAGIC_HASH
Definition: rsaenh.c:55
#define NTE_BAD_UID
Definition: winerror.h:2869
#define RSAENH_MAGIC_CONTAINER
Definition: rsaenh.c:126

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 }
#define TRUE
Definition: types.h:120
#define NTE_BAD_KEY
Definition: winerror.h:2871
static HCRYPTPROV hProv
Definition: rsaenh.c:32
#define TRACE(s)
Definition: solgame.cpp:4
BOOL is_valid_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType)
Definition: handle.c:96
#define SetLastError(x)
Definition: compat.h:417
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:82
BOOL release_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType)
Definition: handle.c:230
#define NTE_BAD_UID
Definition: winerror.h:2869
#define RSAENH_MAGIC_CONTAINER
Definition: rsaenh.c:126

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 
2084  *phHash = new_object(&handle_table, sizeof(CRYPTHASH), RSAENH_MAGIC_HASH,
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 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define NTE_BAD_HASH
Definition: winerror.h:2870
_In_ HCRYPTHASH hHash
Definition: wincrypt.h:4198
HASH_CONTEXT context
Definition: rsaenh.c:73
CRYPT_DATA_BLOB blobSeed
Definition: rsaenh.c:62
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
BOOL duplicate_hash_impl(ALG_ID aiAlgid, const HASH_CONTEXT *pSrcHashContext, HASH_CONTEXT *pDestHashContext)
Definition: implglue.c:173
static BOOL copy_hmac_info(PHMAC_INFO *dst, const HMAC_INFO *src)
Definition: rsaenh.c:573
static void destroy_hash(OBJECTHDR *pObject)
Definition: rsaenh.c:612
HCRYPTKEY new_object(struct handle_table *lpTable, size_t cbSize, DWORD dwType, DESTRUCTOR destructor, OBJECTHDR **ppObject)
Definition: handle.c:353
static BOOL copy_data_blob(PCRYPT_DATA_BLOB dst, const PCRYPT_DATA_BLOB src)
Definition: rsaenh.c:476
#define TRACE(s)
Definition: solgame.cpp:4
BOOL is_valid_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType)
Definition: handle.c:96
PHMAC_INFO pHMACInfo
Definition: rsaenh.c:75
#define SetLastError(x)
Definition: compat.h:417
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
CRYPT_DATA_BLOB blobLabel
Definition: rsaenh.c:61
_Reserved_ DWORD * pdwReserved
Definition: wincrypt.h:4254
ULONG_PTR HCRYPTHASH
Definition: wincrypt.h:50
RSAENH_TLS1PRF_PARAMS tpPRFParams
Definition: rsaenh.c:76
#define RSAENH_MAGIC_HASH
Definition: rsaenh.c:55
#define NTE_BAD_UID
Definition: winerror.h:2869
#define RSAENH_MAGIC_CONTAINER
Definition: rsaenh.c:126
BOOL lookup_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType, OBJECTHDR **lplpObject)
Definition: handle.c:275

◆ 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 
2128  if (!lookup_handle(&handle_table, hKey, RSAENH_MAGIC_KEY, (OBJECTHDR**)&pSrcKey))
2129  {
2131  return FALSE;
2132  }
2133 
2134  if (!phKey || pdwReserved || dwFlags)
2135  {