ReactOS  0.4.13-dev-99-g7e18b6d
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 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 150 of file rsaenh.c.

◆ RSAENH_3DES112_STORAGE_KEYLEN

#define RSAENH_3DES112_STORAGE_KEYLEN   128

Definition at line 151 of file rsaenh.c.

◆ RSAENH_3DES_EFFECTIVE_KEYLEN

#define RSAENH_3DES_EFFECTIVE_KEYLEN   168

Definition at line 152 of file rsaenh.c.

◆ RSAENH_3DES_STORAGE_KEYLEN

#define RSAENH_3DES_STORAGE_KEYLEN   192

Definition at line 153 of file rsaenh.c.

◆ RSAENH_DECRYPT

#define RSAENH_DECRYPT   0

Definition at line 143 of file rsaenh.c.

◆ RSAENH_DES_EFFECTIVE_KEYLEN

#define RSAENH_DES_EFFECTIVE_KEYLEN   56

Definition at line 148 of file rsaenh.c.

◆ RSAENH_DES_STORAGE_KEYLEN

#define RSAENH_DES_STORAGE_KEYLEN   64

Definition at line 149 of file rsaenh.c.

◆ RSAENH_ENCRYPT

#define RSAENH_ENCRYPT   1

Definition at line 142 of file rsaenh.c.

◆ RSAENH_HASHSTATE_FINISHED

#define RSAENH_HASHSTATE_FINISHED   2

Definition at line 57 of file rsaenh.c.

◆ RSAENH_HASHSTATE_HASHING

#define RSAENH_HASHSTATE_HASHING   1

Definition at line 56 of file rsaenh.c.

◆ RSAENH_HMAC_BLOCK_LEN

#define RSAENH_HMAC_BLOCK_LEN   64

Definition at line 147 of file rsaenh.c.

◆ RSAENH_HMAC_DEF_IPAD_CHAR

#define RSAENH_HMAC_DEF_IPAD_CHAR   0x36

Definition at line 144 of file rsaenh.c.

◆ RSAENH_HMAC_DEF_OPAD_CHAR

#define RSAENH_HMAC_DEF_OPAD_CHAR   0x5c

Definition at line 145 of file rsaenh.c.

◆ RSAENH_HMAC_DEF_PAD_LEN

#define RSAENH_HMAC_DEF_PAD_LEN   64

Definition at line 146 of file rsaenh.c.

◆ RSAENH_KEYSTATE_ENCRYPTING

#define RSAENH_KEYSTATE_ENCRYPTING   1

Definition at line 85 of file rsaenh.c.

◆ RSAENH_KEYSTATE_IDLE

#define RSAENH_KEYSTATE_IDLE   0

Definition at line 84 of file rsaenh.c.

◆ RSAENH_KEYSTATE_MASTERKEY

#define RSAENH_KEYSTATE_MASTERKEY   2

Definition at line 86 of file rsaenh.c.

◆ RSAENH_MAGIC_CONTAINER

#define RSAENH_MAGIC_CONTAINER   0x26384993u

Definition at line 125 of file rsaenh.c.

◆ RSAENH_MAGIC_HASH

#define RSAENH_MAGIC_HASH   0x85938417u

Definition at line 54 of file rsaenh.c.

◆ RSAENH_MAGIC_KEY

#define RSAENH_MAGIC_KEY   0x73620457u

Definition at line 81 of file rsaenh.c.

◆ RSAENH_MAGIC_RSA1

#define RSAENH_MAGIC_RSA1   0x31415352

Definition at line 155 of file rsaenh.c.

◆ RSAENH_MAGIC_RSA2

#define RSAENH_MAGIC_RSA2   0x32415352

Definition at line 154 of file rsaenh.c.

◆ RSAENH_MAX_BLOCK_SIZE

#define RSAENH_MAX_BLOCK_SIZE   24

Definition at line 83 of file rsaenh.c.

◆ RSAENH_MAX_ENUMALGS

#define RSAENH_MAX_ENUMALGS   24

Definition at line 167 of file rsaenh.c.

◆ RSAENH_MAX_HASH_SIZE

#define RSAENH_MAX_HASH_SIZE   104

Definition at line 55 of file rsaenh.c.

◆ RSAENH_MAX_KEY_SIZE

#define RSAENH_MAX_KEY_SIZE   64

Definition at line 82 of file rsaenh.c.

◆ RSAENH_MIN

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

Definition at line 163 of file rsaenh.c.

◆ RSAENH_PCT1_SSL2_SSL3_TLS1

Definition at line 168 of file rsaenh.c.

◆ RSAENH_PERSONALITY_AES

#define RSAENH_PERSONALITY_AES   4u

Definition at line 123 of file rsaenh.c.

◆ RSAENH_PERSONALITY_BASE

#define RSAENH_PERSONALITY_BASE   0u

Definition at line 119 of file rsaenh.c.

◆ RSAENH_PERSONALITY_ENHANCED

#define RSAENH_PERSONALITY_ENHANCED   2u

Definition at line 121 of file rsaenh.c.

◆ RSAENH_PERSONALITY_SCHANNEL

#define RSAENH_PERSONALITY_SCHANNEL   3u

Definition at line 122 of file rsaenh.c.

◆ RSAENH_PERSONALITY_STRONG

#define RSAENH_PERSONALITY_STRONG   1u

Definition at line 120 of file rsaenh.c.

◆ RSAENH_PKC_BLOCKTYPE

#define RSAENH_PKC_BLOCKTYPE   0x02

Definition at line 156 of file rsaenh.c.

◆ RSAENH_REGKEY

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

Definition at line 161 of file rsaenh.c.

◆ RSAENH_SSL3_VERSION_MAJOR

#define RSAENH_SSL3_VERSION_MAJOR   3

Definition at line 157 of file rsaenh.c.

◆ RSAENH_SSL3_VERSION_MINOR

#define RSAENH_SSL3_VERSION_MINOR   0

Definition at line 158 of file rsaenh.c.

◆ RSAENH_TLS1_VERSION_MAJOR

#define RSAENH_TLS1_VERSION_MAJOR   3

Definition at line 159 of file rsaenh.c.

◆ RSAENH_TLS1_VERSION_MINOR

#define RSAENH_TLS1_VERSION_MINOR   1

Definition at line 160 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 1468 of file rsaenh.c.

1470 {
1471  /* These prefixes are meant to be concatenated with hash values of the
1472  * respective kind to form a PKCS #7 DigestInfo. */
1473  static const struct tagOIDDescriptor {
1474  ALG_ID aiAlgid;
1475  DWORD dwLen;
1476  const BYTE abOID[19];
1477  } aOIDDescriptor[] = {
1478  { CALG_MD2, 18, { 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48,
1479  0x86, 0xf7, 0x0d, 0x02, 0x02, 0x05, 0x00, 0x04, 0x10 } },
1480  { CALG_MD4, 18, { 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48,
1481  0x86, 0xf7, 0x0d, 0x02, 0x04, 0x05, 0x00, 0x04, 0x10 } },
1482  { CALG_MD5, 18, { 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48,
1483  0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10 } },
1484  { CALG_SHA, 15, { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03,
1485  0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 } },
1486  { CALG_SHA_256, 19, { 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
1487  0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01,
1488  0x05, 0x00, 0x04, 0x20 } },
1489  { CALG_SHA_384, 19, { 0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
1490  0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02,
1491  0x05, 0x00, 0x04, 0x30 } },
1492  { CALG_SHA_512, 19, { 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
1493  0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03,
1494  0x05, 0x00, 0x04, 0x40 } },
1495  { CALG_SSL3_SHAMD5, 0, { 0 } },
1496  { 0, 0, { 0 } }
1497  };
1498  DWORD dwIdxOID, i, j;
1499 
1500  for (dwIdxOID = 0; aOIDDescriptor[dwIdxOID].aiAlgid; dwIdxOID++) {
1501  if (aOIDDescriptor[dwIdxOID].aiAlgid == aiAlgid) break;
1502  }
1503 
1504  if (!aOIDDescriptor[dwIdxOID].aiAlgid) {
1506  return FALSE;
1507  }
1508 
1509  /* Build the padded signature */
1510  if (dwFlags & CRYPT_X931_FORMAT) {
1511  pbSignature[0] = 0x6b;
1512  for (i=1; i < dwLen - dwHashLen - 3; i++) {
1513  pbSignature[i] = 0xbb;
1514  }
1515  pbSignature[i++] = 0xba;
1516  for (j=0; j < dwHashLen; j++, i++) {
1517  pbSignature[i] = abHashValue[j];
1518  }
1519  pbSignature[i++] = 0x33;
1520  pbSignature[i++] = 0xcc;
1521  } else {
1522  pbSignature[0] = 0x00;
1523  pbSignature[1] = 0x01;
1524  if (dwFlags & CRYPT_NOHASHOID) {
1525  for (i=2; i < dwLen - 1 - dwHashLen; i++) {
1526  pbSignature[i] = 0xff;
1527  }
1528  pbSignature[i++] = 0x00;
1529  } else {
1530  for (i=2; i < dwLen - 1 - aOIDDescriptor[dwIdxOID].dwLen - dwHashLen; i++) {
1531  pbSignature[i] = 0xff;
1532  }
1533  pbSignature[i++] = 0x00;
1534  for (j=0; j < aOIDDescriptor[dwIdxOID].dwLen; j++) {
1535  pbSignature[i++] = aOIDDescriptor[dwIdxOID].abOID[j];
1536  }
1537  }
1538  for (j=0; j < dwHashLen; j++) {
1539  pbSignature[i++] = abHashValue[j];
1540  }
1541  }
1542 
1543  return TRUE;
1544 }
#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:409
_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 504 of file rsaenh.c.

506 {
507  dst->cbData = src1->cbData + src2->cbData;
508  dst->pbData = HeapAlloc(GetProcessHeap(), 0, dst->cbData);
509  if (!dst->pbData) {
511  return FALSE;
512  }
513  memcpy(dst->pbData, src1->pbData, src1->cbData);
514  memcpy(dst->pbData + src1->cbData, src2->pbData, src2->cbData);
515  return TRUE;
516 }
#define NTE_NO_MEMORY
Definition: winerror.h:2882
#define TRUE
Definition: types.h:120
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define SetLastError(x)
Definition: compat.h:409
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 475 of file rsaenh.c.

476 {
477  dst->pbData = HeapAlloc(GetProcessHeap(), 0, src->cbData);
478  if (!dst->pbData) {
480  return FALSE;
481  }
482  dst->cbData = src->cbData;
483  memcpy(dst->pbData, src->pbData, src->cbData);
484  return TRUE;
485 }
#define NTE_NO_MEMORY
Definition: winerror.h:2882
#define TRUE
Definition: types.h:120
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define SetLastError(x)
Definition: compat.h:409
#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 572 of file rsaenh.c.

572  {
573  if (!src) return FALSE;
574  *dst = HeapAlloc(GetProcessHeap(), 0, sizeof(HMAC_INFO));
575  if (!*dst) return FALSE;
576  **dst = *src;
577  (*dst)->pbInnerString = NULL;
578  (*dst)->pbOuterString = NULL;
579  if ((*dst)->cbInnerString == 0) (*dst)->cbInnerString = RSAENH_HMAC_DEF_PAD_LEN;
580  (*dst)->pbInnerString = HeapAlloc(GetProcessHeap(), 0, (*dst)->cbInnerString);
581  if (!(*dst)->pbInnerString) {
583  return FALSE;
584  }
585  if (src->cbInnerString)
586  memcpy((*dst)->pbInnerString, src->pbInnerString, src->cbInnerString);
587  else
589  if ((*dst)->cbOuterString == 0) (*dst)->cbOuterString = RSAENH_HMAC_DEF_PAD_LEN;
590  (*dst)->pbOuterString = HeapAlloc(GetProcessHeap(), 0, (*dst)->cbOuterString);
591  if (!(*dst)->pbOuterString) {
593  return FALSE;
594  }
595  if (src->cbOuterString)
596  memcpy((*dst)->pbOuterString, src->pbOuterString, src->cbOuterString);
597  else
599  return TRUE;
600 }
#define RSAENH_HMAC_DEF_PAD_LEN
Definition: rsaenh.c:146
#define TRUE
Definition: types.h:120
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
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:549
#define RSAENH_HMAC_DEF_OPAD_CHAR
Definition: rsaenh.c:145
GLenum GLenum dst
Definition: glext.h:6340
#define RSAENH_HMAC_DEF_IPAD_CHAR
Definition: rsaenh.c:144
#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 402 of file rsaenh.c.

404 {
405  if (pbBuffer)
406  {
407  if (dwParamSize > *pdwBufferSize)
408  {
410  *pdwBufferSize = dwParamSize;
411  return FALSE;
412  }
413  memcpy(pbBuffer, pbParam, dwParamSize);
414  }
415  *pdwBufferSize = dwParamSize;
416  return TRUE;
417 }
#define TRUE
Definition: types.h:120
#define SetLastError(x)
Definition: compat.h:409
#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 1102 of file rsaenh.c.

1103 {
1104  CHAR szRSABase[MAX_PATH];
1105  HKEY hRootKey;
1106 
1107  sprintf(szRSABase, RSAENH_REGKEY, pKeyContainer->szName);
1108 
1109  if (pKeyContainer->dwFlags & CRYPT_MACHINE_KEYSET)
1110  hRootKey = HKEY_LOCAL_MACHINE;
1111  else
1112  hRootKey = HKEY_CURRENT_USER;
1113 
1114  /* @@ Wine registry key: HKLM\Software\Wine\Crypto\RSA */
1115  /* @@ Wine registry key: HKCU\Software\Wine\Crypto\RSA */
1116  return RegCreateKeyExA(hRootKey, szRSABase, 0, NULL,
1117  REG_OPTION_NON_VOLATILE, sam, NULL, phKey, NULL)
1118  == ERROR_SUCCESS;
1119 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HKEY_CURRENT_USER
Definition: winreg.h:11
char CHAR
Definition: xmlstorage.h:175
#define sprintf(buf, format,...)
Definition: sprintf.c:55
smooth NULL
Definition: ftsmooth.c:416
#define RSAENH_REGKEY
Definition: rsaenh.c:161
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define MAX_PATH
Definition: compat.h:26
#define CRYPT_MACHINE_KEYSET
Definition: wincrypt.h:2072
DWORD dwFlags
Definition: rsaenh.c:129
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:1032
CHAR szName[MAX_PATH]
Definition: rsaenh.c:133
#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 2620 of file rsaenh.c.

2623 {
2624  CRYPTKEY *pPubKey;
2625 
2626  if (dwFlags & CRYPT_SSL2_FALLBACK) {
2627  if (pCryptKey->aiAlgid != CALG_SSL2_MASTER) {
2629  return FALSE;
2630  }
2631  }
2632 
2633  switch ((BYTE)dwBlobType)
2634  {
2635  case SIMPLEBLOB:
2636  if (!lookup_handle(&handle_table, hPubKey, RSAENH_MAGIC_KEY, (OBJECTHDR**)&pPubKey)){
2637  SetLastError(NTE_BAD_PUBLIC_KEY); /* FIXME: error_code? */
2638  return FALSE;
2639  }
2640  return crypt_export_simple(pCryptKey, pPubKey, dwFlags, pbData,
2641  pdwDataLen);
2642 
2643  case PUBLICKEYBLOB:
2644  if (is_valid_handle(&handle_table, hPubKey, RSAENH_MAGIC_KEY)) {
2645  SetLastError(NTE_BAD_KEY); /* FIXME: error code? */
2646  return FALSE;
2647  }
2648 
2649  return crypt_export_public_key(pCryptKey, pbData, pdwDataLen);
2650 
2651  case PRIVATEKEYBLOB:
2652  return crypt_export_private_key(pCryptKey, force, pbData, pdwDataLen);
2653 
2654  case PLAINTEXTKEYBLOB:
2655  return crypt_export_plaintext_key(pCryptKey, pbData, pdwDataLen);
2656 
2657  default:
2658  SetLastError(NTE_BAD_TYPE); /* FIXME: error code? */
2659  return FALSE;
2660  }
2661 }
#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:2456
#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:2496
#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:2572
#define SetLastError(x)
Definition: compat.h:409
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:81
static BOOL crypt_export_private_key(CRYPTKEY *pCryptKey, BOOL force, BYTE *pbData, DWORD *pdwDataLen)
Definition: rsaenh.c:2531
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
unsigned char BYTE
Definition: mem.h:68
ALG_ID aiAlgid
Definition: rsaenh.c:98
#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 2572 of file rsaenh.c.

2574 {
2575  BLOBHEADER *pBlobHeader = (BLOBHEADER*)pbData;
2576  DWORD *pKeyLen = (DWORD*)(pBlobHeader+1);
2577  BYTE *pbKey = (BYTE*)(pKeyLen+1);
2578  DWORD dwDataLen;
2579 
2580  dwDataLen = sizeof(BLOBHEADER) + sizeof(DWORD) + pCryptKey->dwKeyLen;
2581  if (pbData) {
2582  if (*pdwDataLen < dwDataLen) {
2584  *pdwDataLen = dwDataLen;
2585  return FALSE;
2586  }
2587 
2588  pBlobHeader->bType = PLAINTEXTKEYBLOB;
2589  pBlobHeader->bVersion = CUR_BLOB_VERSION;
2590  pBlobHeader->reserved = 0;
2591  pBlobHeader->aiKeyAlg = pCryptKey->aiAlgid;
2592 
2593  *pKeyLen = pCryptKey->dwKeyLen;
2594  memcpy(pbKey, pCryptKey->abKeyValue, pCryptKey->dwKeyLen);
2595  }
2596  *pdwDataLen = dwDataLen;
2597  return TRUE;
2598 }
#define TRUE
Definition: types.h:120
ALG_ID aiKeyAlg
Definition: wincrypt.h:139
DWORD dwKeyLen
Definition: rsaenh.c:103
struct _PUBLICKEYSTRUC BLOBHEADER
BYTE abKeyValue[RSAENH_MAX_KEY_SIZE]
Definition: rsaenh.c:109
_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:409
#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:98
#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 2531 of file rsaenh.c.

2533 {
2534  BLOBHEADER *pBlobHeader = (BLOBHEADER*)pbData;
2535  RSAPUBKEY *pRSAPubKey = (RSAPUBKEY*)(pBlobHeader+1);
2536  DWORD dwDataLen;
2537 
2538  if ((pCryptKey->aiAlgid != CALG_RSA_KEYX) && (pCryptKey->aiAlgid != CALG_RSA_SIGN)) {
2540  return FALSE;
2541  }
2542  if (!force && !(pCryptKey->dwPermissions & CRYPT_EXPORT))
2543  {
2545  return FALSE;
2546  }
2547 
2548  dwDataLen = sizeof(BLOBHEADER) + sizeof(RSAPUBKEY) +
2549  2 * pCryptKey->dwKeyLen + 5 * ((pCryptKey->dwKeyLen + 1) >> 1);
2550  if (pbData) {
2551  if (*pdwDataLen < dwDataLen) {
2553  *pdwDataLen = dwDataLen;
2554  return FALSE;
2555  }
2556 
2557  pBlobHeader->bType = PRIVATEKEYBLOB;
2558  pBlobHeader->bVersion = CUR_BLOB_VERSION;
2559  pBlobHeader->reserved = 0;
2560  pBlobHeader->aiKeyAlg = pCryptKey->aiAlgid;
2561 
2562  pRSAPubKey->magic = RSAENH_MAGIC_RSA2;
2563  pRSAPubKey->bitlen = pCryptKey->dwKeyLen << 3;
2564 
2565  export_private_key_impl((BYTE*)(pRSAPubKey+1), &pCryptKey->context,
2566  pCryptKey->dwKeyLen, &pRSAPubKey->pubexp);
2567  }
2568  *pdwDataLen = dwDataLen;
2569  return TRUE;
2570 }
#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:103
#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:102
DWORD pubexp
Definition: wincrypt.h:145
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
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:98
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:154
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201
KEY_CONTEXT context
Definition: rsaenh.c:108
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 2496 of file rsaenh.c.

2498 {
2499  BLOBHEADER *pBlobHeader = (BLOBHEADER*)pbData;
2500  RSAPUBKEY *pRSAPubKey = (RSAPUBKEY*)(pBlobHeader+1);
2501  DWORD dwDataLen;
2502 
2503  if ((pCryptKey->aiAlgid != CALG_RSA_KEYX) && (pCryptKey->aiAlgid != CALG_RSA_SIGN)) {
2505  return FALSE;
2506  }
2507 
2508  dwDataLen = sizeof(BLOBHEADER) + sizeof(RSAPUBKEY) + pCryptKey->dwKeyLen;
2509  if (pbData) {
2510  if (*pdwDataLen < dwDataLen) {
2512  *pdwDataLen = dwDataLen;
2513  return FALSE;
2514  }
2515 
2516  pBlobHeader->bType = PUBLICKEYBLOB;
2517  pBlobHeader->bVersion = CUR_BLOB_VERSION;
2518  pBlobHeader->reserved = 0;
2519  pBlobHeader->aiKeyAlg = pCryptKey->aiAlgid;
2520 
2521  pRSAPubKey->magic = RSAENH_MAGIC_RSA1;
2522  pRSAPubKey->bitlen = pCryptKey->dwKeyLen << 3;
2523 
2524  export_public_key_impl((BYTE*)(pRSAPubKey+1), &pCryptKey->context,
2525  pCryptKey->dwKeyLen, &pRSAPubKey->pubexp);
2526  }
2527  *pdwDataLen = dwDataLen;
2528  return TRUE;
2529 }
#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:103
#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:155
#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:409
unsigned char BYTE
Definition: mem.h:68
#define ERROR_MORE_DATA
Definition: dderror.h:13
ALG_ID aiAlgid
Definition: rsaenh.c:98
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:108

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 2456 of file rsaenh.c.

2458 {
2459  BLOBHEADER *pBlobHeader = (BLOBHEADER*)pbData;
2460  ALG_ID *pAlgid = (ALG_ID*)(pBlobHeader+1);
2461  DWORD dwDataLen;
2462 
2464  SetLastError(NTE_BAD_KEY); /* FIXME: error code? */
2465  return FALSE;
2466  }
2467 
2468  dwDataLen = sizeof(BLOBHEADER) + sizeof(ALG_ID) + pPubKey->dwBlockLen;
2469  if (pbData) {
2470  if (*pdwDataLen < dwDataLen) {
2472  *pdwDataLen = dwDataLen;
2473  return FALSE;
2474  }
2475 
2476  pBlobHeader->bType = SIMPLEBLOB;
2477  pBlobHeader->bVersion = CUR_BLOB_VERSION;
2478  pBlobHeader->reserved = 0;
2479  pBlobHeader->aiKeyAlg = pCryptKey->aiAlgid;
2480 
2481  *pAlgid = pPubKey->aiAlgid;
2482 
2483  if (!pad_data(pCryptKey->abKeyValue, pCryptKey->dwKeyLen, (BYTE*)(pAlgid+1),
2484  pPubKey->dwBlockLen, dwFlags))
2485  {
2486  return FALSE;
2487  }
2488 
2489  encrypt_block_impl(pPubKey->aiAlgid, PK_PUBLIC, &pPubKey->context, (BYTE*)(pAlgid+1),
2490  (BYTE*)(pAlgid+1), RSAENH_ENCRYPT);
2491  }
2492  *pdwDataLen = dwDataLen;
2493  return TRUE;
2494 }
#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:103
struct _PUBLICKEYSTRUC BLOBHEADER
DWORD dwBlockLen
Definition: rsaenh.c:106
BYTE abKeyValue[RSAENH_MAX_KEY_SIZE]
Definition: rsaenh.c:109
#define RSAENH_ENCRYPT
Definition: rsaenh.c:142
#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:409
_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:1692
#define ERROR_MORE_DATA
Definition: dderror.h:13
ALG_ID aiAlgid
Definition: rsaenh.c:98
#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:108

Referenced by crypt_export_key().

◆ delete_container_key()

static BOOL delete_container_key ( LPCSTR  pszContainerName,
DWORD  dwFlags 
)
static

Definition at line 1160 of file rsaenh.c.

1161 {
1162  CHAR szRegKey[MAX_PATH];
1163 
1164  if (snprintf(szRegKey, MAX_PATH, RSAENH_REGKEY, pszContainerName) >= MAX_PATH) {
1166  return FALSE;
1167  } else {
1168  HKEY hRootKey;
1170  hRootKey = HKEY_LOCAL_MACHINE;
1171  else
1172  hRootKey = HKEY_CURRENT_USER;
1173  if (!RegDeleteKeyA(hRootKey, szRegKey)) {
1175  return TRUE;
1176  } else {
1178  return FALSE;
1179  }
1180  }
1181 }
#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:161
#define MAX_PATH
Definition: compat.h:26
#define NTE_BAD_KEYSET
Definition: winerror.h:2890
#define SetLastError(x)
Definition: compat.h:409
_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:1225
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by RSAENH_CPAcquireContext().

◆ destroy_hash()

static void destroy_hash ( OBJECTHDR pObject)
static

Definition at line 611 of file rsaenh.c.

612 {
613  CRYPTHASH *pCryptHash = (CRYPTHASH*)pObject;
614 
615  free_hmac_info(pCryptHash->pHMACInfo);
616  free_data_blob(&pCryptHash->tpPRFParams.blobLabel);
617  free_data_blob(&pCryptHash->tpPRFParams.blobSeed);
618  HeapFree(GetProcessHeap(), 0, pCryptHash);
619 }
CRYPT_DATA_BLOB blobSeed
Definition: rsaenh.c:61
#define GetProcessHeap()
Definition: compat.h:395
PHMAC_INFO pHMACInfo
Definition: rsaenh.c:74
static void free_data_blob(PCRYPT_DATA_BLOB pBlob)
Definition: rsaenh.c:526
CRYPT_DATA_BLOB blobLabel
Definition: rsaenh.c:60
static void free_hmac_info(PHMAC_INFO hmac_info)
Definition: rsaenh.c:549
RSAENH_TLS1PRF_PARAMS tpPRFParams
Definition: rsaenh.c:75
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by RSAENH_CPCreateHash(), and RSAENH_CPDuplicateHash().

◆ destroy_key()

static void destroy_key ( OBJECTHDR pObject)
static

Definition at line 748 of file rsaenh.c.

749 {
750  CRYPTKEY *pCryptKey = (CRYPTKEY*)pObject;
751 
752  free_key_impl(pCryptKey->aiAlgid, &pCryptKey->context);
755  free_data_blob(&pCryptKey->blobHmacKey);
756  HeapFree(GetProcessHeap(), 0, pCryptKey);
757 }
RSAENH_SCHANNEL_INFO siSChannelInfo
Definition: rsaenh.c:112
BOOL free_key_impl(ALG_ID aiAlgid, KEY_CONTEXT *pKeyContext)
Definition: implglue.c:197
#define GetProcessHeap()
Definition: compat.h:395
CRYPT_DATA_BLOB blobClientRandom
Definition: rsaenh.c:91
static void free_data_blob(PCRYPT_DATA_BLOB pBlob)
Definition: rsaenh.c:526
CRYPT_DATA_BLOB blobServerRandom
Definition: rsaenh.c:92
ALG_ID aiAlgid
Definition: rsaenh.c:98
CRYPT_DATA_BLOB blobHmacKey
Definition: rsaenh.c:113
#define HeapFree(x, y, z)
Definition: compat.h:394
KEY_CONTEXT context
Definition: rsaenh.c:108

Referenced by new_key(), and RSAENH_CPDuplicateKey().

◆ destroy_key_container()

static void destroy_key_container ( OBJECTHDR pObjectHdr)
static

Definition at line 1262 of file rsaenh.c.

1263 {
1264  KEYCONTAINER *pKeyContainer = (KEYCONTAINER*)pObjectHdr;
1265 
1266  if (!(pKeyContainer->dwFlags & CRYPT_VERIFYCONTEXT))
1267  {
1268  store_key_container_keys(pKeyContainer);
1269  store_key_container_permissions(pKeyContainer);
1270  release_key_container_keys(pKeyContainer);
1271  }
1272  else
1273  release_key_container_keys(pKeyContainer);
1274  HeapFree( GetProcessHeap(), 0, pKeyContainer );
1275 }
static void store_key_container_permissions(KEYCONTAINER *pKeyContainer)
Definition: rsaenh.c:1224
static void release_key_container_keys(KEYCONTAINER *pKeyContainer)
Definition: rsaenh.c:1246
#define GetProcessHeap()
Definition: compat.h:395
static void store_key_container_keys(KEYCONTAINER *pKeyContainer)
Definition: rsaenh.c:1191
#define CRYPT_VERIFYCONTEXT
Definition: wincrypt.h:2069
DWORD dwFlags
Definition: rsaenh.c:129
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by new_key_container().

◆ DllMain()

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

Definition at line 366 of file rsaenh.c.

367 {
368  switch (fdwReason)
369  {
370  case DLL_PROCESS_ATTACH:
374  break;
375 
376  case DLL_PROCESS_DETACH:
377  if (reserved) break;
379  break;
380  }
381  return TRUE;
382 }
#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:2655
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:49

◆ DllRegisterServer()

HRESULT WINAPI DllRegisterServer ( void  )

Definition at line 4652 of file rsaenh.c.

4653 {
4655 }
HRESULT __wine_register_resources(HMODULE module) DECLSPEC_HIDDEN
Definition: register.c:98
static HINSTANCE instance
Definition: rsaenh.c:49

◆ DllUnregisterServer()

HRESULT WINAPI DllUnregisterServer ( void  )

Definition at line 4660 of file rsaenh.c.

4661 {
4663 }
HRESULT __wine_unregister_resources(HMODULE module) DECLSPEC_HIDDEN
Definition: register.c:110
static HINSTANCE instance
Definition: rsaenh.c:49

◆ finalize_hash()

static void finalize_hash ( CRYPTHASH pCryptHash)
inlinestatic

Definition at line 705 of file rsaenh.c.

705  {
706  DWORD dwDataLen;
707 
708  switch (pCryptHash->aiAlgid)
709  {
710  case CALG_HMAC:
711  if (pCryptHash->pHMACInfo) {
712  BYTE abHashValue[RSAENH_MAX_HASH_SIZE];
713 
714  finalize_hash_impl(pCryptHash->pHMACInfo->HashAlgid, &pCryptHash->context,
715  pCryptHash->abHashValue);
716  memcpy(abHashValue, pCryptHash->abHashValue, pCryptHash->dwHashSize);
717  init_hash_impl(pCryptHash->pHMACInfo->HashAlgid, &pCryptHash->context);
718  update_hash_impl(pCryptHash->pHMACInfo->HashAlgid, &pCryptHash->context,
719  pCryptHash->pHMACInfo->pbOuterString,
720  pCryptHash->pHMACInfo->cbOuterString);
721  update_hash_impl(pCryptHash->pHMACInfo->HashAlgid, &pCryptHash->context,
722  abHashValue, pCryptHash->dwHashSize);
723  finalize_hash_impl(pCryptHash->pHMACInfo->HashAlgid, &pCryptHash->context,
724  pCryptHash->abHashValue);
725  }
726  break;
727 
728  case CALG_MAC:
729  dwDataLen = 0;
730  RSAENH_CPEncrypt(pCryptHash->hProv, pCryptHash->hKey, 0, TRUE, 0,
731  pCryptHash->abHashValue, &dwDataLen, pCryptHash->dwHashSize);
732  break;
733 
734  default:
735  finalize_hash_impl(pCryptHash->aiAlgid, &pCryptHash->context, pCryptHash->abHashValue);
736  }
737 }
ALG_ID HashAlgid
Definition: wincrypt.h:94
HCRYPTPROV hProv
Definition: rsaenh.c:69
#define TRUE
Definition: types.h:120
DWORD cbOuterString
Definition: wincrypt.h:98
HASH_CONTEXT context
Definition: rsaenh.c:72
#define RSAENH_MAX_HASH_SIZE
Definition: rsaenh.c:55
BYTE abHashValue[RSAENH_MAX_HASH_SIZE]
Definition: rsaenh.c:73
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:74
HCRYPTKEY hKey
Definition: rsaenh.c:68
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:67
#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:70
BOOL WINAPI RSAENH_CPEncrypt(HCRYPTPROV hProv, HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen, DWORD dwBufLen)
Definition: rsaenh.c:2182
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 526 of file rsaenh.c.

526  {
527  HeapFree(GetProcessHeap(), 0, pBlob->pbData);
528 }
#define GetProcessHeap()
Definition: compat.h:395
BYTE * pbData
Definition: wincrypt.h:103
#define HeapFree(x, y, z)
Definition: compat.h:394

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 549 of file rsaenh.c.

549  {
550  if (!hmac_info) return;
551  HeapFree(GetProcessHeap(), 0, hmac_info->pbInnerString);
552  HeapFree(GetProcessHeap(), 0, hmac_info->pbOuterString);
553  HeapFree(GetProcessHeap(), 0, hmac_info);
554 }
BYTE * pbInnerString
Definition: wincrypt.h:95
#define GetProcessHeap()
Definition: compat.h:395
BYTE * pbOuterString
Definition: wincrypt.h:97
#define HeapFree(x, y, z)
Definition: compat.h:394

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 445 of file rsaenh.c.

445  {
446  const PROV_ENUMALGS_EX *iterator;
447  KEYCONTAINER *pKeyContainer;
448 
449  if (!(pKeyContainer = get_key_container(hProv))) return NULL;
450 
451  for (iterator = aProvEnumAlgsEx[pKeyContainer->dwPersonality]; iterator->aiAlgid; iterator++) {
452  if (iterator->aiAlgid == algid) return iterator;
453  }
454 
456  return NULL;
457 }
#define NTE_BAD_ALGID
Definition: winerror.h:2876
static HCRYPTPROV hProv
Definition: rsaenh.c:32
DWORD dwPersonality
Definition: rsaenh.c:130
smooth NULL
Definition: ftsmooth.c:416
#define SetLastError(x)
Definition: compat.h:409
static KEYCONTAINER * get_key_container(HCRYPTPROV hProv)
Definition: rsaenh.c:419
static const PROV_ENUMALGS_EX aProvEnumAlgsEx[5][RSAENH_MAX_ENUMALGS+1]
Definition: rsaenh.c:169

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 419 of file rsaenh.c.

420 {
421  KEYCONTAINER *pKeyContainer;
422 
424  (OBJECTHDR**)&pKeyContainer))
425  {
427  return NULL;
428  }
429  return pKeyContainer;
430 }
static HCRYPTPROV hProv
Definition: rsaenh.c:32
smooth NULL
Definition: ftsmooth.c:416
#define SetLastError(x)
Definition: compat.h:409
#define NTE_BAD_UID
Definition: winerror.h:2869
#define RSAENH_MAGIC_CONTAINER
Definition: rsaenh.c:125
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 3065 of file rsaenh.c.

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

2989 {
2990  CRYPTKEY *pCryptKey;
2991  const BLOBHEADER *pBlobHeader = (const BLOBHEADER*)pbData;
2992  const DWORD *pKeyLen = (const DWORD *)(pBlobHeader + 1);
2993  const BYTE *pbKeyStream = (const BYTE*)(pKeyLen + 1);
2994 
2995  if (dwDataLen < sizeof(BLOBHEADER)+sizeof(DWORD)+*pKeyLen)
2996  {
2997  SetLastError(NTE_BAD_DATA); /* FIXME: error code */
2998  return FALSE;
2999  }
3000 
3002  {
3003  *phKey = new_key(hProv, CALG_HMAC, 0, &pCryptKey);
3004  if (*phKey == (HCRYPTKEY)INVALID_HANDLE_VALUE)
3005  return FALSE;
3006  if (*pKeyLen <= RSAENH_MIN(sizeof(pCryptKey->abKeyValue), RSAENH_HMAC_BLOCK_LEN))
3007  {
3008  memcpy(pCryptKey->abKeyValue, pbKeyStream, *pKeyLen);
3009  pCryptKey->dwKeyLen = *pKeyLen;
3010  }
3011  else
3012  {
3013  CRYPT_DATA_BLOB blobHmacKey = { *pKeyLen, (BYTE *)pbKeyStream };
3014 
3015  /* In order to initialize an HMAC key, the key material is hashed,
3016  * and the output of the hash function is used as the key material.
3017  * Unfortunately, the way the Crypto API is designed, we don't know
3018  * the hash algorithm yet, so we have to copy the entire key
3019  * material.
3020  */
3021  if (!copy_data_blob(&pCryptKey->blobHmacKey, &blobHmacKey))
3022  {
3024  *phKey = (HCRYPTKEY)INVALID_HANDLE_VALUE;
3025  return FALSE;
3026  }
3027  }
3028  setup_key(pCryptKey);
3029  if (dwFlags & CRYPT_EXPORTABLE)
3030  pCryptKey->dwPermissions |= CRYPT_EXPORT;
3031  }
3032  else
3033  {
3034  *phKey = new_key(hProv, pBlobHeader->aiKeyAlg, *pKeyLen<<19, &pCryptKey);
3035  if (*phKey == (HCRYPTKEY)INVALID_HANDLE_VALUE)
3036  return FALSE;
3037  memcpy(pCryptKey->abKeyValue, pbKeyStream, *pKeyLen);
3038  setup_key(pCryptKey);
3039  if (dwFlags & CRYPT_EXPORTABLE)
3040  pCryptKey->dwPermissions |= CRYPT_EXPORT;
3041  }
3042  return TRUE;
3043 }
#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:147
ALG_ID aiKeyAlg
Definition: wincrypt.h:139
DWORD dwKeyLen
Definition: rsaenh.c:103
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
static HCRYPTPROV hProv
Definition: rsaenh.c:32
static void setup_key(CRYPTKEY *pCryptKey)
Definition: rsaenh.c:767
BYTE abKeyValue[RSAENH_MAX_KEY_SIZE]
Definition: rsaenh.c:109
#define RSAENH_MIN(a, b)
Definition: rsaenh.c:163
static BOOL copy_data_blob(PCRYPT_DATA_BLOB dst, const PCRYPT_DATA_BLOB src)
Definition: rsaenh.c:475
DWORD dwPermissions
Definition: rsaenh.c:102
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:81
_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:113
static DWORD DWORD
Definition: rsaenh.c:111
static HCRYPTKEY new_key(HCRYPTPROV hProv, ALG_ID aiAlgid, DWORD dwFlags, CRYPTKEY **ppCryptKey)
Definition: rsaenh.c:793
_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 2756 of file rsaenh.c.

2758 {
2759  KEYCONTAINER *pKeyContainer;
2760  CRYPTKEY *pCryptKey;
2761  const BLOBHEADER *pBlobHeader = (const BLOBHEADER*)pbData;
2762  const RSAPUBKEY *pRSAPubKey = (const RSAPUBKEY*)(pBlobHeader+1);
2763  BOOL ret;
2764 
2766  {
2767  FIXME("unimplemented for CRYPT_IPSEC_HMAC_KEY\n");
2769  return FALSE;
2770  }
2771  if (!(pKeyContainer = get_key_container(hProv)))
2772  return FALSE;
2773 
2774  if ((dwDataLen < sizeof(BLOBHEADER) + sizeof(RSAPUBKEY)))
2775  {
2776  ERR("datalen %d not long enough for a BLOBHEADER + RSAPUBKEY\n",
2777  dwDataLen);
2779  return FALSE;
2780  }
2781  if (pRSAPubKey->magic != RSAENH_MAGIC_RSA2)
2782  {
2783  ERR("unexpected magic %08x\n", pRSAPubKey->magic);
2785  return FALSE;
2786  }
2787  if ((dwDataLen < sizeof(BLOBHEADER) + sizeof(RSAPUBKEY) +
2788  (pRSAPubKey->bitlen >> 3) + (5 * ((pRSAPubKey->bitlen+8)>>4))))
2789  {
2790  DWORD expectedLen = sizeof(BLOBHEADER) + sizeof(RSAPUBKEY) +
2791  (pRSAPubKey->bitlen >> 3) + (5 * ((pRSAPubKey->bitlen+8)>>4));
2792 
2793  ERR("blob too short for pub key: expect %d, got %d\n",
2794  expectedLen, dwDataLen);
2796  return FALSE;
2797  }
2798 
2799  *phKey = new_key(hProv, pBlobHeader->aiKeyAlg, MAKELONG(0,pRSAPubKey->bitlen), &pCryptKey);
2800  if (*phKey == (HCRYPTKEY)INVALID_HANDLE_VALUE) return FALSE;
2801  setup_key(pCryptKey);
2802  ret = import_private_key_impl((const BYTE*)(pRSAPubKey+1), &pCryptKey->context,
2803  pRSAPubKey->bitlen/8, dwDataLen, pRSAPubKey->pubexp);
2804  if (ret) {
2805  if (dwFlags & CRYPT_EXPORTABLE)
2806  pCryptKey->dwPermissions |= CRYPT_EXPORT;
2807  switch (pBlobHeader->aiKeyAlg)
2808  {
2809  case AT_SIGNATURE:
2810  case CALG_RSA_SIGN:
2811  TRACE("installing signing key\n");
2812  release_and_install_key(hProv, *phKey, &pKeyContainer->hSignatureKeyPair,
2813  fStoreKey);
2814  break;
2815  case AT_KEYEXCHANGE:
2816  case CALG_RSA_KEYX:
2817  TRACE("installing key exchange key\n");
2818  release_and_install_key(hProv, *phKey, &pKeyContainer->hKeyExchangeKeyPair,
2819  fStoreKey);
2820  break;
2821  }
2822  }
2823  return ret;
2824 }
#define CRYPT_IPSEC_HMAC_KEY
Definition: wincrypt.h:91
#define NTE_BAD_DATA
Definition: winerror.h:2873
HCRYPTKEY hSignatureKeyPair
Definition: rsaenh.c:136
ALG_ID aiKeyAlg
Definition: wincrypt.h:139
#define CALG_RSA_SIGN
Definition: wincrypt.h:1816
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD magic
Definition: wincrypt.h:143
static HCRYPTPROV hProv
Definition: rsaenh.c:32
HCRYPTKEY hKeyExchangeKeyPair
Definition: rsaenh.c:135
#define AT_KEYEXCHANGE
Definition: wincrypt.h:2035
struct _PUBLICKEYSTRUC BLOBHEADER
static void setup_key(CRYPTKEY *pCryptKey)
Definition: rsaenh.c:767
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:102
#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:409
static void release_and_install_key(HCRYPTPROV hProv, HCRYPTKEY src, HCRYPTKEY *dest, DWORD fStoreKey)
Definition: rsaenh.c:2716
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:419
#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:154
static HCRYPTKEY new_key(HCRYPTPROV hProv, ALG_ID aiAlgid, DWORD dwFlags, CRYPTKEY **ppCryptKey)
Definition: rsaenh.c:793
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201
KEY_CONTEXT context
Definition: rsaenh.c:108

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 2848 of file rsaenh.c.

2850 {
2851  CRYPTKEY *pCryptKey;
2852  const BLOBHEADER *pBlobHeader = (const BLOBHEADER*)pbData;
2853  const RSAPUBKEY *pRSAPubKey = (const RSAPUBKEY*)(pBlobHeader+1);
2854  ALG_ID algID;
2855  BOOL ret;
2856 
2858  {
2859  FIXME("unimplemented for CRYPT_IPSEC_HMAC_KEY\n");
2861  return FALSE;
2862  }
2863 
2864  if ((dwDataLen < sizeof(BLOBHEADER) + sizeof(RSAPUBKEY)) ||
2865  (pRSAPubKey->magic != RSAENH_MAGIC_RSA1) ||
2866  (dwDataLen < sizeof(BLOBHEADER) + sizeof(RSAPUBKEY) + (pRSAPubKey->bitlen >> 3)))
2867  {
2869  return FALSE;
2870  }
2871 
2872  /* Since this is a public key blob, only the public key is
2873  * available, so only signature verification is possible.
2874  */
2875  algID = pBlobHeader->aiKeyAlg;
2876  *phKey = new_key(hProv, algID, MAKELONG(0,pRSAPubKey->bitlen), &pCryptKey);
2877  if (*phKey == (HCRYPTKEY)INVALID_HANDLE_VALUE) return FALSE;
2878  setup_key(pCryptKey);
2879  ret = import_public_key_impl((const BYTE*)(pRSAPubKey+1), &pCryptKey->context,
2880  pRSAPubKey->bitlen >> 3, pRSAPubKey->pubexp);
2881  if (ret) {
2882  if (dwFlags & CRYPT_EXPORTABLE)
2883  pCryptKey->dwPermissions |= CRYPT_EXPORT;
2884  }
2885  return ret;
2886 }
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:391
DWORD magic
Definition: wincrypt.h:143
static HCRYPTPROV hProv
Definition: rsaenh.c:32
static void setup_key(CRYPTKEY *pCryptKey)
Definition: rsaenh.c:767
#define RSAENH_MAGIC_RSA1
Definition: rsaenh.c:155
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:102
DWORD pubexp
Definition: wincrypt.h:145
#define SetLastError(x)
Definition: compat.h:409
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:793
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201
KEY_CONTEXT context
Definition: rsaenh.c:108

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 2911 of file rsaenh.c.

2913 {
2914  CRYPTKEY *pCryptKey, *pPubKey;
2915  const BLOBHEADER *pBlobHeader = (const BLOBHEADER*)pbData;
2916  const ALG_ID *pAlgid = (const ALG_ID*)(pBlobHeader+1);
2917  const BYTE *pbKeyStream = (const BYTE*)(pAlgid + 1);
2918  BYTE *pbDecrypted;
2919  DWORD dwKeyLen;
2920 
2922  {
2923  FIXME("unimplemented for CRYPT_IPSEC_HMAC_KEY\n");
2925  return FALSE;
2926  }
2927  if (!lookup_handle(&handle_table, hPubKey, RSAENH_MAGIC_KEY, (OBJECTHDR**)&pPubKey) ||
2928  pPubKey->aiAlgid != CALG_RSA_KEYX)
2929  {
2930  SetLastError(NTE_BAD_PUBLIC_KEY); /* FIXME: error code? */
2931  return FALSE;
2932  }
2933 
2934  if (dwDataLen < sizeof(BLOBHEADER)+sizeof(ALG_ID)+pPubKey->dwBlockLen)
2935  {
2936  SetLastError(NTE_BAD_DATA); /* FIXME: error code */
2937  return FALSE;
2938  }
2939 
2940  pbDecrypted = HeapAlloc(GetProcessHeap(), 0, pPubKey->dwBlockLen);
2941  if (!pbDecrypted) return FALSE;
2942  encrypt_block_impl(pPubKey->aiAlgid, PK_PRIVATE, &pPubKey->context, pbKeyStream, pbDecrypted,
2943  RSAENH_DECRYPT);
2944 
2945  dwKeyLen = RSAENH_MAX_KEY_SIZE;
2946  if (!unpad_data(pbDecrypted, pPubKey->dwBlockLen, pbDecrypted, &dwKeyLen, dwFlags)) {
2947  HeapFree(GetProcessHeap(), 0, pbDecrypted);
2948  return FALSE;
2949  }
2950 
2951  *phKey = new_key(hProv, pBlobHeader->aiKeyAlg, dwKeyLen<<19, &pCryptKey);
2952  if (*phKey == (HCRYPTKEY)INVALID_HANDLE_VALUE)
2953  {
2954  HeapFree(GetProcessHeap(), 0, pbDecrypted);
2955  return FALSE;
2956  }
2957  memcpy(pCryptKey->abKeyValue, pbDecrypted, dwKeyLen);
2958  HeapFree(GetProcessHeap(), 0, pbDecrypted);
2959  setup_key(pCryptKey);
2960  if (dwFlags & CRYPT_EXPORTABLE)
2961  pCryptKey->dwPermissions |= CRYPT_EXPORT;
2962  return TRUE;
2963 }
#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:391
#define NTE_BAD_PUBLIC_KEY
Definition: winerror.h:2889
static HCRYPTPROV hProv
Definition: rsaenh.c:32
#define RSAENH_MAX_KEY_SIZE
Definition: rsaenh.c:82
static BOOL unpad_data(const BYTE *abData, DWORD dwDataLen, BYTE *abBuffer, DWORD *dwBufferLen, DWORD dwFlags)
Definition: rsaenh.c:1733
static void setup_key(CRYPTKEY *pCryptKey)
Definition: rsaenh.c:767
#define FIXME(fmt,...)
Definition: debug.h:110
BYTE abKeyValue[RSAENH_MAX_KEY_SIZE]
Definition: rsaenh.c:109
#define CALG_RSA_KEYX
Definition: wincrypt.h:1824
#define PK_PRIVATE
Definition: tomcrypt.h:449
DWORD dwPermissions
Definition: rsaenh.c:102
#define GetProcessHeap()
Definition: compat.h:395
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:409
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:81
_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:143
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:394
static HCRYPTKEY new_key(HCRYPTPROV hProv, ALG_ID aiAlgid, DWORD dwFlags, CRYPTKEY **ppCryptKey)
Definition: rsaenh.c:793
_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 533 of file rsaenh.c.

533  {
534  pBlob->pbData = NULL;
535  pBlob->cbData = 0;
536 }
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 629 of file rsaenh.c.

629  {
630  DWORD dwLen;
631 
632  switch (pCryptHash->aiAlgid)
633  {
634  case CALG_HMAC:
635  if (pCryptHash->pHMACInfo) {
636  const PROV_ENUMALGS_EX *pAlgInfo;
637 
638  pAlgInfo = get_algid_info(pCryptHash->hProv, pCryptHash->pHMACInfo->HashAlgid);
639  if (!pAlgInfo) return FALSE;
640  pCryptHash->dwHashSize = pAlgInfo->dwDefaultLen >> 3;
641  init_hash_impl(pCryptHash->pHMACInfo->HashAlgid, &pCryptHash->context);
642  update_hash_impl(pCryptHash->pHMACInfo->HashAlgid, &pCryptHash->context,
643  pCryptHash->pHMACInfo->pbInnerString,
644  pCryptHash->pHMACInfo->cbInnerString);
645  }
646  return TRUE;
647 
648  case CALG_MAC:
649  dwLen = sizeof(DWORD);
650  RSAENH_CPGetKeyParam(pCryptHash->hProv, pCryptHash->hKey, KP_BLOCKLEN,
651  (BYTE*)&pCryptHash->dwHashSize, &dwLen, 0);
652  pCryptHash->dwHashSize >>= 3;
653  return TRUE;
654 
655  default:
656  return init_hash_impl(pCryptHash->aiAlgid, &pCryptHash->context);
657  }
658 }
ALG_ID HashAlgid
Definition: wincrypt.h:94
HCRYPTPROV hProv
Definition: rsaenh.c:69
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:3600
HASH_CONTEXT context
Definition: rsaenh.c:72
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:74
HCRYPTKEY hKey
Definition: rsaenh.c:68
unsigned long DWORD
Definition: ntddk_ex.h:95
static const PROV_ENUMALGS_EX * get_algid_info(HCRYPTPROV hProv, ALG_ID algid)
Definition: rsaenh.c:445
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:67
#define CALG_HMAC
Definition: wincrypt.h:1810
#define CALG_MAC
Definition: wincrypt.h:1808
DWORD dwHashSize
Definition: rsaenh.c:70
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 968 of file rsaenh.c.

969 {
970  LPCSTR szValueName;
971 
972  switch (dwKeySpec)
973  {
974  case AT_KEYEXCHANGE:
975  szValueName = "KeyExchangeKeyPair";
976  break;
977  case AT_SIGNATURE:
978  szValueName = "SignatureKeyPair";
979  break;
980  default:
981  WARN("invalid key spec %d\n", dwKeySpec);
982  szValueName = NULL;
983  }
984  return szValueName;
985 }
#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 1049 of file rsaenh.c.

1050 {
1051  LPCSTR szValueName;
1052 
1053  switch (dwKeySpec)
1054  {
1055  case AT_KEYEXCHANGE:
1056  szValueName = "KeyExchangePermissions";
1057  break;
1058  case AT_SIGNATURE:
1059  szValueName = "SignaturePermissions";
1060  break;
1061  default:
1062  WARN("invalid key spec %d\n", dwKeySpec);
1063  szValueName = NULL;
1064  }
1065  return szValueName;
1066 }
#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 793 of file rsaenh.c.

794 {
795  HCRYPTKEY hCryptKey;
796  CRYPTKEY *pCryptKey;
797  DWORD dwKeyLen = HIWORD(dwFlags), bKeyLen = dwKeyLen;
798  const PROV_ENUMALGS_EX *peaAlgidInfo;
799 
800  *ppCryptKey = NULL;
801 
802  /*
803  * Retrieve the CSP's capabilities for the given ALG_ID value
804  */
805  peaAlgidInfo = get_algid_info(hProv, aiAlgid);
806  if (!peaAlgidInfo) return (HCRYPTKEY)INVALID_HANDLE_VALUE;
807 
808  TRACE("alg = %s, dwKeyLen = %d\n", debugstr_a(peaAlgidInfo->szName),
809  dwKeyLen);
810  /*
811  * Assume the default key length, if none is specified explicitly
812  */
813  if (dwKeyLen == 0) dwKeyLen = peaAlgidInfo->dwDefaultLen;
814 
815  /*
816  * Check if the requested key length is supported by the current CSP.
817  * Adjust key length's for DES algorithms.
818  */
819  switch (aiAlgid) {
820  case CALG_DES:
821  if (dwKeyLen == RSAENH_DES_EFFECTIVE_KEYLEN) {
822  dwKeyLen = RSAENH_DES_STORAGE_KEYLEN;
823  }
824  if (dwKeyLen != RSAENH_DES_STORAGE_KEYLEN) {
827  }
828  break;
829 
830  case CALG_3DES_112:
831  if (dwKeyLen == RSAENH_3DES112_EFFECTIVE_KEYLEN) {
833  }
834  if (dwKeyLen != RSAENH_3DES112_STORAGE_KEYLEN) {
837  }
838  break;
839 
840  case CALG_3DES:
841  if (dwKeyLen == RSAENH_3DES_EFFECTIVE_KEYLEN) {
842  dwKeyLen = RSAENH_3DES_STORAGE_KEYLEN;
843  }
844  if (dwKeyLen != RSAENH_3DES_STORAGE_KEYLEN) {
847  }
848  break;
849 
850  case CALG_HMAC:
851  /* Avoid the key length check for HMAC keys, which have unlimited
852  * length.
853  */
854  break;
855 
856  case CALG_AES:
857  if (!bKeyLen)
858  {
859  TRACE("missing key len for CALG_AES\n");
862  }
863  /* fall through */
864  default:
865  if (dwKeyLen % 8 ||
866  dwKeyLen > peaAlgidInfo->dwMaxLen ||
867  dwKeyLen < peaAlgidInfo->dwMinLen)
868  {
869  TRACE("key len %d out of bounds (%d, %d)\n", dwKeyLen,
870  peaAlgidInfo->dwMinLen, peaAlgidInfo->dwMaxLen);
873  }
874  }
875 
876  hCryptKey = new_object(&handle_table, sizeof(CRYPTKEY), RSAENH_MAGIC_KEY,
877  destroy_key, (OBJECTHDR**)&pCryptKey);
878  if (hCryptKey != (HCRYPTKEY)INVALID_HANDLE_VALUE)
879  {
880  KEYCONTAINER *pKeyContainer = get_key_container(hProv);
881  pCryptKey->aiAlgid = aiAlgid;
882  pCryptKey->hProv = hProv;
883  pCryptKey->dwModeBits = 0;
885  CRYPT_MAC;
887  pCryptKey->dwPermissions |= CRYPT_EXPORT;
888  pCryptKey->dwKeyLen = dwKeyLen >> 3;
889  pCryptKey->dwEffectiveKeyLen = 0;
890 
891  /*
892  * For compatibility reasons a 40 bit key on the Enhanced
893  * provider will not have salt
894  */
895  if (pKeyContainer->dwPersonality == RSAENH_PERSONALITY_ENHANCED
896  && (aiAlgid == CALG_RC2 || aiAlgid == CALG_RC4)
897  && (dwFlags & CRYPT_CREATE_SALT) && dwKeyLen == 40)
898  pCryptKey->dwSaltLen = 0;
899  else if ((dwFlags & CRYPT_CREATE_SALT) || (dwKeyLen == 40 && !(dwFlags & CRYPT_NO_SALT)))
900  pCryptKey->dwSaltLen = 16 /*FIXME*/ - pCryptKey->dwKeyLen;
901  else
902  pCryptKey->dwSaltLen = 0;
903  memset(pCryptKey->abKeyValue, 0, sizeof(pCryptKey->abKeyValue));
904  memset(pCryptKey->abInitVector, 0, sizeof(pCryptKey->abInitVector));
905  memset(&pCryptKey->siSChannelInfo.saEncAlg, 0, sizeof(pCryptKey->siSChannelInfo.saEncAlg));
906  memset(&pCryptKey->siSChannelInfo.saMACAlg, 0, sizeof(pCryptKey->siSChannelInfo.saMACAlg));
909  init_data_blob(&pCryptKey->blobHmacKey);
910 
911  switch(aiAlgid)
912  {
913  case CALG_PCT1_MASTER:
914  case CALG_SSL2_MASTER:
915  case CALG_SSL3_MASTER:
916  case CALG_TLS1_MASTER:
917  case CALG_RC4:
918  pCryptKey->dwBlockLen = 0;
919  pCryptKey->dwMode = 0;
920  break;
921 
922  case CALG_RC2:
923  case CALG_DES:
924  case CALG_3DES_112:
925  case CALG_3DES:
926  pCryptKey->dwBlockLen = 8;
927  pCryptKey->dwMode = CRYPT_MODE_CBC;
928  break;
929 
930  case CALG_AES:
931  case CALG_AES_128:
932  case CALG_AES_192:
933  case CALG_AES_256:
934  pCryptKey->dwBlockLen = 16;
935  pCryptKey->dwMode = CRYPT_MODE_CBC;
936  break;
937 
938  case CALG_RSA_KEYX:
939  case CALG_RSA_SIGN:
940  pCryptKey->dwBlockLen = dwKeyLen >> 3;
941  pCryptKey->dwMode = 0;
942  break;
943 
944  case CALG_HMAC:
945  pCryptKey->dwBlockLen = 0;
946  pCryptKey->dwMode = 0;
947  break;
948  }
949 
950  *ppCryptKey = pCryptKey;
951  }
952 
953  return hCryptKey;
954 }
#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:150
#define CRYPT_NO_SALT
Definition: wincrypt.h:2210
DWORD dwKeyLen
Definition: rsaenh.c:103
SCHANNEL_ALG saMACAlg
Definition: rsaenh.c:90
#define CALG_RSA_SIGN
Definition: wincrypt.h:1816
#define CALG_RC4
Definition: wincrypt.h:1837
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define CRYPT_ENCRYPT
Definition: wincrypt.h:2195
static void destroy_key(OBJECTHDR *pObject)
Definition: rsaenh.c:748
#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:106
#define CALG_SSL2_MASTER
Definition: wincrypt.h:1848
BYTE abKeyValue[RSAENH_MAX_KEY_SIZE]
Definition: rsaenh.c:109
RSAENH_SCHANNEL_INFO siSChannelInfo
Definition: rsaenh.c:112
DWORD dwPersonality
Definition: rsaenh.c:130
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:102
#define TRACE(s)
Definition: solgame.cpp:4
CRYPT_DATA_BLOB blobClientRandom
Definition: rsaenh.c:91
#define debugstr_a
Definition: kernel32.h:31
CRYPT_DATA_BLOB blobServerRandom
Definition: rsaenh.c:92
#define RSAENH_DES_STORAGE_KEYLEN
Definition: rsaenh.c:149
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
static const PROV_ENUMALGS_EX * get_algid_info(HCRYPTPROV hProv, ALG_ID algid)
Definition: rsaenh.c:445
#define CALG_SSL3_MASTER
Definition: wincrypt.h:1843
DWORD dwEffectiveKeyLen
Definition: rsaenh.c:104
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:81
#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:419
#define CALG_AES_128
Definition: wincrypt.h:1833
ALG_ID aiAlgid
Definition: rsaenh.c:98
DWORD dwModeBits
Definition: rsaenh.c:101
BYTE abInitVector[RSAENH_MAX_BLOCK_SIZE]
Definition: rsaenh.c:110
DWORD dwSaltLen
Definition: rsaenh.c:105
#define RSAENH_3DES112_STORAGE_KEYLEN
Definition: rsaenh.c:151
SCHANNEL_ALG saEncAlg
Definition: rsaenh.c:89
#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:533
DWORD dwMode
Definition: rsaenh.c:100
#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:152
HCRYPTPROV hProv
Definition: rsaenh.c:99
CRYPT_DATA_BLOB blobHmacKey
Definition: rsaenh.c:113
#define memset(x, y, z)
Definition: compat.h:39
#define CRYPT_WRITE
Definition: wincrypt.h:2199
#define RSAENH_PERSONALITY_ENHANCED
Definition: rsaenh.c:121
#define RSAENH_DES_EFFECTIVE_KEYLEN
Definition: rsaenh.c:148
DWORD dwDefaultLen
Definition: wincrypt.h:69
#define RSAENH_3DES_STORAGE_KEYLEN
Definition: rsaenh.c:153

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 1291 of file rsaenh.c.

1292 {
1293  KEYCONTAINER *pKeyContainer;
1294  HCRYPTPROV hKeyContainer;
1295 
1296  hKeyContainer = new_object(&handle_table, sizeof(KEYCONTAINER), RSAENH_MAGIC_CONTAINER,
1297  destroy_key_container, (OBJECTHDR**)&pKeyContainer);
1298  if (hKeyContainer != (HCRYPTPROV)INVALID_HANDLE_VALUE)
1299  {
1300  lstrcpynA(pKeyContainer->szName, pszContainerName, MAX_PATH);
1301  pKeyContainer->dwFlags = dwFlags;
1302  pKeyContainer->dwEnumAlgsCtr = 0;
1305  if (pVTable && pVTable->pszProvName) {
1306  lstrcpynA(pKeyContainer->szProvName, pVTable->pszProvName, MAX_PATH);
1307  if (!strcmp(pVTable->pszProvName, MS_DEF_PROV_A)) {
1308  pKeyContainer->dwPersonality = RSAENH_PERSONALITY_BASE;
1309  } else if (!strcmp(pVTable->pszProvName, MS_ENHANCED_PROV_A)) {
1310  pKeyContainer->dwPersonality = RSAENH_PERSONALITY_ENHANCED;
1311  } else if (!strcmp(pVTable->pszProvName, MS_DEF_RSA_SCHANNEL_PROV_A)) {
1312  pKeyContainer->dwPersonality = RSAENH_PERSONALITY_SCHANNEL;
1313  } else if (!strcmp(pVTable->pszProvName, MS_ENH_RSA_AES_PROV_A) ||
1315  pKeyContainer->dwPersonality = RSAENH_PERSONALITY_AES;
1316  } else {
1317  pKeyContainer->dwPersonality = RSAENH_PERSONALITY_STRONG;
1318  }
1319  }
1320 
1321  /* The new key container has to be inserted into the CSP immediately
1322  * after creation to be available for CPGetProvParam's PP_ENUMCONTAINERS. */
1323  if (!(dwFlags & CRYPT_VERIFYCONTEXT)) {
1324  HKEY hKey;
1325 
1326  if (create_container_key(pKeyContainer, KEY_WRITE, &hKey))
1327  RegCloseKey(hKey);
1328  }
1329  }
1330 
1331  return hKeyContainer;
1332 }
CHAR szProvName[MAX_PATH]
Definition: rsaenh.c:134
HCRYPTKEY hSignatureKeyPair
Definition: rsaenh.c:136
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
static BOOL create_container_key(KEYCONTAINER *pKeyContainer, REGSAM sam, HKEY *phKey)
Definition: rsaenh.c:1102
#define RSAENH_PERSONALITY_SCHANNEL
Definition: rsaenh.c:122
HCRYPTKEY hKeyExchangeKeyPair
Definition: rsaenh.c:135
#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:120
#define MS_ENHANCED_PROV_A
Definition: wincrypt.h:1874
DWORD dwPersonality
Definition: rsaenh.c:130
#define RSAENH_PERSONALITY_AES
Definition: rsaenh.c:123
#define RSAENH_PERSONALITY_BASE
Definition: rsaenh.c:119
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:1262
#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:131
#define CRYPT_VERIFYCONTEXT
Definition: wincrypt.h:2069
DWORD dwFlags
Definition: rsaenh.c:129
ULONG_PTR HCRYPTPROV
Definition: wincrypt.h:46
#define lstrcpynA
Definition: compat.h:408
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:125
CHAR szName[MAX_PATH]
Definition: rsaenh.c:133
#define RSAENH_PERSONALITY_ENHANCED
Definition: rsaenh.c:121

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 1133 of file rsaenh.c.

1134 {
1135  CHAR szRSABase[MAX_PATH];
1136  HKEY hRootKey;
1137 
1138  sprintf(szRSABase, RSAENH_REGKEY, pszContainerName);
1139 
1141  hRootKey = HKEY_LOCAL_MACHINE;
1142  else
1143  hRootKey = HKEY_CURRENT_USER;
1144 
1145  /* @@ Wine registry key: HKLM\Software\Wine\Crypto\RSA */
1146  /* @@ Wine registry key: HKCU\Software\Wine\Crypto\RSA */
1147  return RegOpenKeyExA(hRootKey, szRSABase, 0, access, phKey) ==
1148  ERROR_SUCCESS;
1149 }
#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:3346
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define RSAENH_REGKEY
Definition: rsaenh.c:161
#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 1692 of file rsaenh.c.

1694 {
1695  DWORD i;
1696 
1697  /* Ensure there is enough space for PKCS1 #2 padding */
1698  if (dwDataLen > dwBufferLen-11) {
1700  return FALSE;
1701  }
1702 
1703  memmove(abBuffer + dwBufferLen - dwDataLen, abData, dwDataLen);
1704 
1705  abBuffer[0] = 0x00;
1706  abBuffer[1] = RSAENH_PKC_BLOCKTYPE;
1707  for (i=2; i < dwBufferLen - dwDataLen - 1; i++)
1708  do gen_rand_impl(&abBuffer[i], 1); while (!abBuffer[i]);
1710  for (i-=8; i < dwBufferLen - dwDataLen - 1; i++)
1711  abBuffer[i] = 0x03;
1712  abBuffer[i] = 0x00;
1713 
1714  return TRUE;
1715 }
#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:409
_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:156

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 1411 of file rsaenh.c.

1412 {
1413  HKEY hKey;
1414  KEYCONTAINER *pKeyContainer;
1415  HCRYPTPROV hKeyContainer;
1416  HCRYPTKEY hCryptKey;
1417 
1418  if (!open_container_key(pszContainerName, dwFlags, KEY_READ, &hKey))
1419  {
1422  }
1423 
1424  hKeyContainer = new_key_container(pszContainerName, dwFlags, pVTable);
1425  if (hKeyContainer != (HCRYPTPROV)INVALID_HANDLE_VALUE)
1426  {
1427  DWORD dwProtectFlags = (dwFlags & CRYPT_MACHINE_KEYSET) ?
1429 
1430  if (!lookup_handle(&handle_table, hKeyContainer, RSAENH_MAGIC_CONTAINER,
1431  (OBJECTHDR**)&pKeyContainer))
1433 
1434  /* read_key_value calls import_key, which calls import_private_key,
1435  * which implicitly installs the key value into the appropriate key
1436  * container key. Thus the ref count is incremented twice, once for
1437  * the output key value, and once for the implicit install, and needs
1438  * to be decremented to balance the two.
1439  */
1440  if (read_key_value(hKeyContainer, hKey, AT_KEYEXCHANGE,
1441  dwProtectFlags, &hCryptKey))
1443  if (read_key_value(hKeyContainer, hKey, AT_SIGNATURE,
1444  dwProtectFlags, &hCryptKey))
1446  }
1447 
1448  return hKeyContainer;
1449 }
static BOOL read_key_value(HCRYPTPROV hKeyContainer, HKEY hKey, DWORD dwKeySpec, DWORD dwFlags, HCRYPTKEY *phCryptKey)
Definition: rsaenh.c:1346
#define KEY_READ
Definition: nt_native.h:1023
static BOOL open_container_key(LPCSTR pszContainerName, DWORD dwFlags, REGSAM access, HKEY *phKey)
Definition: rsaenh.c:1133
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
static HCRYPTPROV new_key_container(PCCH pszContainerName, DWORD dwFlags, const VTableProvStruc *pVTable)
Definition: rsaenh.c:1291
#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:409
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:81
_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:125
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 1346 of file rsaenh.c.

1347 {
1348  LPCSTR szValueName;
1349  DWORD dwValueType, dwLen;
1350  BYTE *pbKey;
1351  DATA_BLOB blobIn, blobOut;
1352  BOOL ret = FALSE;
1353 
1354  if (!(szValueName = map_key_spec_to_key_pair_name(dwKeySpec)))
1355  return FALSE;
1356  if (RegQueryValueExA(hKey, szValueName, 0, &dwValueType, NULL, &dwLen) ==
1357  ERROR_SUCCESS)
1358  {
1359  pbKey = HeapAlloc(GetProcessHeap(), 0, dwLen);
1360  if (pbKey)
1361  {
1362  if (RegQueryValueExA(hKey, szValueName, 0, &dwValueType, pbKey, &dwLen) ==
1363  ERROR_SUCCESS)
1364  {
1365  blobIn.pbData = pbKey;
1366  blobIn.cbData = dwLen;
1367 
1368  if (CryptUnprotectData(&blobIn, NULL, NULL, NULL, NULL,
1369  dwFlags, &blobOut))
1370  {
1371  ret = import_key(hKeyContainer, blobOut.pbData, blobOut.cbData, 0, 0,
1372  FALSE, phCryptKey);
1373  LocalFree(blobOut.pbData);
1374  }
1375  }
1376  HeapFree(GetProcessHeap(), 0, pbKey);
1377  }
1378  }
1379  if (ret)
1380  {
1381  CRYPTKEY *pKey;
1382 
1383  if (lookup_handle(&handle_table, *phCryptKey, RSAENH_MAGIC_KEY,
1384  (OBJECTHDR**)&pKey))
1385  {
1386  if ((szValueName = map_key_spec_to_permissions_name(dwKeySpec)))
1387  {
1388  dwLen = sizeof(pKey->dwPermissions);
1389  RegQueryValueExA(hKey, szValueName, 0, NULL,
1390  (BYTE *)&pKey->dwPermissions, &dwLen);
1391  }
1392  }
1393  }
1394  return ret;
1395 }
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:4041
#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:3065
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:81
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:968
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
static LPCSTR map_key_spec_to_permissions_name(DWORD dwKeySpec)
Definition: rsaenh.c:1049
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:394

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 2716 of file rsaenh.c.

2718 {
2721  if (fStoreKey)
2722  {
2723  KEYCONTAINER *pKeyContainer;
2724 
2725  if ((pKeyContainer = get_key_container(hProv)))
2726  {
2727  store_key_container_keys(pKeyContainer);
2728  store_key_container_permissions(pKeyContainer);
2729  }
2730  }
2731 }
static void store_key_container_permissions(KEYCONTAINER *pKeyContainer)
Definition: rsaenh.c:1224
static HCRYPTPROV hProv
Definition: rsaenh.c:32
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:81
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:1191
static KEYCONTAINER * get_key_container(HCRYPTPROV hProv)
Definition: rsaenh.c:419
BOOL WINAPI RSAENH_CPDestroyKey(HCRYPTPROV hProv, HCRYPTKEY hKey)
Definition: rsaenh.c:2022
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 1246 of file rsaenh.c.

1247 {
1252 }
HCRYPTKEY hSignatureKeyPair
Definition: rsaenh.c:136
HCRYPTKEY hKeyExchangeKeyPair
Definition: rsaenh.c:135
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:81
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 1784 of file rsaenh.c.

1786 {
1787  CHAR szKeyContainerName[MAX_PATH];
1788 
1789  TRACE("(phProv=%p, pszContainer=%s, dwFlags=%08x, pVTable=%p)\n", phProv,
1790  debugstr_a(pszContainer), dwFlags, pVTable);
1791 
1792  if (pszContainer && *pszContainer)
1793  {
1794  lstrcpynA(szKeyContainerName, pszContainer, MAX_PATH);
1795  }
1796  else
1797  {
1798  DWORD dwLen = sizeof(szKeyContainerName);
1799  if (!GetUserNameA(szKeyContainerName, &dwLen)) return FALSE;
1800  }
1801 
1803  {
1804  case 0:
1805  *phProv = read_key_container(szKeyContainerName, dwFlags, pVTable);
1806  break;
1807 
1808  case CRYPT_DELETEKEYSET:
1809  return delete_container_key(szKeyContainerName, dwFlags);
1810 
1811  case CRYPT_NEWKEYSET:
1812  *phProv = read_key_container(szKeyContainerName, dwFlags, pVTable);
1813  if (*phProv != (HCRYPTPROV)INVALID_HANDLE_VALUE)
1814  {
1816  TRACE("Can't create new keyset, already exists\n");
1818  return FALSE;
1819  }
1820  *phProv = new_key_container(szKeyContainerName, dwFlags, pVTable);
1821  break;
1822 
1824  case CRYPT_VERIFYCONTEXT:
1825  if (pszContainer && *pszContainer) {
1826  TRACE("pszContainer should be empty\n");
1828  return FALSE;
1829  }
1830  *phProv = new_key_container("", dwFlags, pVTable);
1831  break;
1832 
1833  default:
1834  *phProv = (HCRYPTPROV)INVALID_HANDLE_VALUE;
1836  return FALSE;
1837  }
1838 
1839  if (*phProv != (HCRYPTPROV)INVALID_HANDLE_VALUE) {
1841  return TRUE;
1842  } else {
1843  return FALSE;
1844  }
1845 }
#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:1411
char CHAR
Definition: xmlstorage.h:175
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
static HCRYPTPROV new_key_container(PCCH pszContainerName, DWORD dwFlags, const VTableProvStruc *pVTable)
Definition: rsaenh.c:1291
#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:409
_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:1160
ULONG_PTR HCRYPTPROV
Definition: wincrypt.h:46
#define NTE_BAD_FLAGS
Definition: winerror.h:2877
#define lstrcpynA
Definition: compat.h:408
#define CRYPT_DELETEKEYSET
Definition: wincrypt.h:2071
#define RSAENH_MAGIC_CONTAINER
Definition: rsaenh.c:125

◆ RSAENH_CPCreateHash()

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

Definition at line 1867 of file rsaenh.c.

1869 {
1870  CRYPTKEY *pCryptKey;
1871  CRYPTHASH *pCryptHash;
1872  const PROV_ENUMALGS_EX *peaAlgidInfo;
1873 
1874  TRACE("(hProv=%08lx, Algid=%08x, hKey=%08lx, dwFlags=%08x, phHash=%p)\n", hProv, Algid, hKey,
1875  dwFlags, phHash);
1876 
1877  peaAlgidInfo = get_algid_info(hProv, Algid);
1878  if (!peaAlgidInfo) return FALSE;
1879 
1880  if (dwFlags)
1881  {
1883  return FALSE;
1884  }
1885 
1886  if (Algid == CALG_MAC || Algid == CALG_HMAC || Algid == CALG_SCHANNEL_MASTER_HASH ||
1887  Algid == CALG_TLS1PRF)
1888  {
1889  if (!lookup_handle(&handle_table, hKey, RSAENH_MAGIC_KEY, (OBJECTHDR**)&pCryptKey)) {
1891  return FALSE;
1892  }
1893 
1894  if ((Algid == CALG_MAC) && (GET_ALG_TYPE(pCryptKey->aiAlgid) != ALG_TYPE_BLOCK)) {
1896  return FALSE;
1897  }
1898 
1899  if ((Algid == CALG_SCHANNEL_MASTER_HASH || Algid == CALG_TLS1PRF) &&
1900  (pCryptKey->aiAlgid != CALG_TLS1_MASTER))
1901  {
1903  return FALSE;
1904  }
1905  if (Algid == CALG_SCHANNEL_MASTER_HASH &&
1906  ((!pCryptKey->siSChannelInfo.blobClientRandom.cbData) ||
1907  (!pCryptKey->siSChannelInfo.blobServerRandom.cbData)))
1908  {
1910  return FALSE;
1911  }
1912 
1913  if ((Algid == CALG_TLS1PRF) && (pCryptKey->dwState != RSAENH_KEYSTATE_MASTERKEY)) {
1915  return FALSE;
1916  }
1917  }
1918 
1919  *phHash = new_object(&handle_table, sizeof(CRYPTHASH), RSAENH_MAGIC_HASH,
1920  destroy_hash, (OBJECTHDR**)&pCryptHash);
1921  if (!pCryptHash) return FALSE;
1922 
1923  pCryptHash->aiAlgid = Algid;
1924  pCryptHash->hKey = hKey;
1925  pCryptHash->hProv = hProv;
1926  pCryptHash->dwState = RSAENH_HASHSTATE_HASHING;
1927  pCryptHash->pHMACInfo = NULL;
1928  pCryptHash->dwHashSize = peaAlgidInfo->dwDefaultLen >> 3;
1929  init_data_blob(&pCryptHash->tpPRFParams.blobLabel);
1930  init_data_blob(&pCryptHash->tpPRFParams.blobSeed);
1931 
1932  if (Algid == CALG_SCHANNEL_MASTER_HASH) {
1933  static const char keyex[] = "key expansion";
1934  BYTE key_expansion[sizeof keyex];
1935  CRYPT_DATA_BLOB blobRandom, blobKeyExpansion = { 13, key_expansion };
1936 
1937  memcpy( key_expansion, keyex, sizeof keyex );
1938 
1939  if (pCryptKey->dwState != RSAENH_KEYSTATE_MASTERKEY) {
1940  static const char msec[] = "master secret";
1941  BYTE master_secret[sizeof msec];
1942  CRYPT_DATA_BLOB blobLabel = { 13, master_secret };
1943  BYTE abKeyValue[48];
1944 
1945  memcpy( master_secret, msec, sizeof msec );
1946 
1947  /* See RFC 2246, chapter 8.1 */
1948  if (!concat_data_blobs(&blobRandom,
1949  &pCryptKey->siSChannelInfo.blobClientRandom,
1950  &pCryptKey->siSChannelInfo.blobServerRandom))
1951  {
1952  return FALSE;
1953  }
1954  tls1_prf(hProv, hKey, &blobLabel, &blobRandom, abKeyValue, 48);
1955  pCryptKey->dwState = RSAENH_KEYSTATE_MASTERKEY;
1956  memcpy(pCryptKey->abKeyValue, abKeyValue, 48);
1957  free_data_blob(&blobRandom);
1958  }
1959 
1960  /* See RFC 2246, chapter 6.3 */
1961  if (!concat_data_blobs(&blobRandom,
1962  &pCryptKey->siSChannelInfo.blobServerRandom,
1963  &pCryptKey->siSChannelInfo.blobClientRandom))
1964  {
1965  return FALSE;
1966  }
1967  tls1_prf(hProv, hKey, &blobKeyExpansion, &blobRandom, pCryptHash->abHashValue,
1969  free_data_blob(&blobRandom);
1970  }
1971 
1972  return init_hash(pCryptHash);
1973 }
#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:69
static BOOL concat_data_blobs(PCRYPT_DATA_BLOB dst, const PCRYPT_DATA_BLOB src1, const PCRYPT_DATA_BLOB src2)
Definition: rsaenh.c:504
#define NTE_BAD_KEY
Definition: winerror.h:2871
#define RSAENH_MAX_HASH_SIZE
Definition: rsaenh.c:55
CRYPT_DATA_BLOB blobSeed
Definition: rsaenh.c:61
#define RSAENH_HASHSTATE_HASHING
Definition: rsaenh.c:56
#define CALG_TLS1_MASTER
Definition: wincrypt.h:1849
static HCRYPTPROV hProv
Definition: rsaenh.c:32
static void destroy_hash(OBJECTHDR *pObject)
Definition: rsaenh.c:611
DWORD dwState
Definition: rsaenh.c:71
BYTE abHashValue[RSAENH_MAX_HASH_SIZE]
Definition: rsaenh.c:73
#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:86
#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:1623
PHMAC_INFO pHMACInfo
Definition: rsaenh.c:74
HCRYPTKEY hKey
Definition: rsaenh.c:68
static void free_data_blob(PCRYPT_DATA_BLOB pBlob)
Definition: rsaenh.c:526
#define SetLastError(x)
Definition: compat.h:409
static const PROV_ENUMALGS_EX * get_algid_info(HCRYPTPROV hProv, ALG_ID algid)
Definition: rsaenh.c:445
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:81
_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:67
CRYPT_DATA_BLOB blobLabel
Definition: rsaenh.c:60
#define CALG_HMAC
Definition: wincrypt.h:1810
static BOOL init_hash(CRYPTHASH *pCryptHash)
Definition: rsaenh.c:629
#define CALG_MAC
Definition: wincrypt.h:1808
RSAENH_TLS1PRF_PARAMS tpPRFParams
Definition: rsaenh.c:75
DWORD dwHashSize
Definition: rsaenh.c:70
#define NTE_BAD_FLAGS
Definition: winerror.h:2877
#define RSAENH_MAGIC_HASH
Definition: rsaenh.c:54
#define NTE_BAD_KEY_STATE
Definition: winerror.h:2879
static void init_data_blob(PCRYPT_DATA_BLOB pBlob)
Definition: rsaenh.c:533
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 2334 of file rsaenh.c.

2336 {
2337  CRYPTKEY *pCryptKey;
2339  DWORD i, j, k;
2340  DWORD dwMax;
2341 
2342  TRACE("(hProv=%08lx, hKey=%08lx, hHash=%08lx, Final=%d, dwFlags=%08x, pbData=%p, "
2343  "pdwDataLen=%p)\n", hProv, hKey, hHash, Final, dwFlags, pbData, pdwDataLen);
2344 
2346  {
2348  return FALSE;
2349  }
2350 
2351  if (dwFlags)
2352  {
2354  return FALSE;
2355  }
2356 
2357  if (!lookup_handle(&handle_table, hKey, RSAENH_MAGIC_KEY, (OBJECTHDR**)&pCryptKey))
2358  {
2360  return FALSE;
2361  }
2362 
2363  if (pCryptKey->dwState == RSAENH_KEYSTATE_IDLE)
2364  pCryptKey->dwState = RSAENH_KEYSTATE_ENCRYPTING;
2365 
2366  if (pCryptKey->dwState != RSAENH_KEYSTATE_ENCRYPTING)
2367  {
2369  return FALSE;
2370  }
2371 
2372  dwMax=*pdwDataLen;
2373 
2374  if (GET_ALG_TYPE(pCryptKey->aiAlgid) == ALG_TYPE_BLOCK) {
2375  for (i=0, in=pbData; i<*pdwDataLen; i+=pCryptKey->dwBlockLen, in+=pCryptKey->dwBlockLen) {
2376  switch (pCryptKey->dwMode) {
2377  case CRYPT_MODE_ECB:
2378  encrypt_block_impl(pCryptKey->aiAlgid, 0, &pCryptKey->context, in, out,
2379  RSAENH_DECRYPT);
2380  break;
2381 
2382  case CRYPT_MODE_CBC:
2383  encrypt_block_impl(pCryptKey->aiAlgid, 0, &pCryptKey->context, in, out,
2384  RSAENH_DECRYPT);
2385  for (j=0; j<pCryptKey->dwBlockLen; j++) out[j] ^= pCryptKey->abChainVector[j];
2386  memcpy(pCryptKey->abChainVector, in, pCryptKey->dwBlockLen);
2387  break;
2388 
2389  case CRYPT_MODE_CFB:
2390  for (j=0; j<pCryptKey->dwBlockLen; j++) {
2391  encrypt_block_impl(pCryptKey->aiAlgid, 0, &pCryptKey->context,
2392  pCryptKey->abChainVector, o, RSAENH_ENCRYPT);
2393  out[j] = in[j] ^ o[0];
2394  for (k=0; k<pCryptKey->dwBlockLen-1; k++)
2395  pCryptKey->abChainVector[k] = pCryptKey->abChainVector[k+1];
2396  pCryptKey->abChainVector[k] = in[j];
2397  }
2398  break;
2399 
2400  default:
2402  return FALSE;
2403  }
2404  memcpy(in, out, pCryptKey->dwBlockLen);
2405  }
2406  if (Final) {
2407  if (pbData[*pdwDataLen-1] &&
2408  pbData[*pdwDataLen-1] <= pCryptKey->dwBlockLen &&
2409  pbData[*pdwDataLen-1] <= *pdwDataLen) {
2410  BOOL padOkay = TRUE;
2411 
2412  /* check that every bad byte has the same value */
2413  for (i = 1; padOkay && i < pbData[*pdwDataLen-1]; i++)
2414  if (pbData[*pdwDataLen - i - 1] != pbData[*pdwDataLen - 1])
2415  padOkay = FALSE;
2416  if (padOkay)
2417  *pdwDataLen -= pbData[*pdwDataLen-1];
2418  else {
2420  setup_key(pCryptKey);
2421  return FALSE;
2422  }
2423  }
2424  else {
2426  setup_key(pCryptKey);
2427  return FALSE;
2428  }
2429  }
2430 
2431  } else if (GET_ALG_TYPE(pCryptKey->aiAlgid) == ALG_TYPE_STREAM) {
2432  encrypt_stream_impl(pCryptKey->aiAlgid, &pCryptKey->context, pbData, *pdwDataLen);
2433  } else if (GET_ALG_TYPE(pCryptKey->aiAlgid) == ALG_TYPE_RSA) {
2434  if (pCryptKey->aiAlgid == CALG_RSA_SIGN) {
2436  return FALSE;
2437  }
2438  encrypt_block_impl(pCryptKey->aiAlgid, PK_PRIVATE, &pCryptKey->context, pbData, pbData, RSAENH_DECRYPT);
2439  if (!unpad_data(pbData, pCryptKey->dwBlockLen, pbData, pdwDataLen, dwFlags)) return FALSE;
2440  Final = TRUE;
2441  } else {
2443  return FALSE;
2444  }
2445 
2446  if (Final) setup_key(pCryptKey);
2447 
2449  if (*pdwDataLen>dwMax ||
2451  }
2452 
2453  return TRUE;
2454 }
#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:4163
#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:1733
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:767
unsigned int BOOL
Definition: ntddk_ex.h:94
#define RSAENH_ENCRYPT
Definition: rsaenh.c:142
_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:85
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:409
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:81
_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:84
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:54
#define RSAENH_MAX_BLOCK_SIZE
Definition: rsaenh.c:83
#define NTE_BAD_UID
Definition: winerror.h:2869
#define RSAENH_MAGIC_CONTAINER
Definition: rsaenh.c:125
#define RSAENH_DECRYPT
Definition: rsaenh.c:143
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 3921 of file rsaenh.c.

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

◆ RSAENH_CPDestroyHash()

BOOL WINAPI RSAENH_CPDestroyHash ( HCRYPTPROV  hProv,
HCRYPTHASH  hHash 
)

Definition at line 1989 of file rsaenh.c.

1990 {
1991  TRACE("(hProv=%08lx, hHash=%08lx)\n", hProv, hHash);
1992 
1994  {
1996  return FALSE;
1997  }
1998 
2000  {
2002  return FALSE;
2003  }
2004 
2005  return TRUE;
2006 }
#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:409
BOOL release_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType)
Definition: handle.c:230
#define RSAENH_MAGIC_HASH
Definition: rsaenh.c:54
#define NTE_BAD_UID
Definition: winerror.h:2869
#define RSAENH_MAGIC_CONTAINER
Definition: rsaenh.c:125

Referenced by RSAENH_CPSetHashParam(), and tls1_prf().

◆ RSAENH_CPDestroyKey()

BOOL WINAPI RSAENH_CPDestroyKey ( HCRYPTPROV  hProv,
HCRYPTKEY  hKey 
)

Definition at line 2022 of file rsaenh.c.

2023 {
2024  TRACE("(hProv=%08lx, hKey=%08lx)\n", hProv, hKey);
2025 
2027  {
2029  return FALSE;
2030  }
2031 
2033  {
2035  return FALSE;
2036  }
2037 
2038  return TRUE;
2039 }
#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:409
#define RSAENH_MAGIC_KEY
Definition: rsaenh.c:81
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:125

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 2057 of file rsaenh.c.

2059 {
2060  CRYPTHASH *pSrcHash, *pDestHash;
2061 
2062  TRACE("(hUID=%08lx, hHash=%08lx, pdwReserved=%p, dwFlags=%08x, phHash=%p)\n", hUID, hHash,
2063  pdwReserved, dwFlags, phHash);
2064 
2066  {
2068  return FALSE;
2069  }
2070 
2072  {
2074  return FALSE;
2075  }
2076 
2077  if (!phHash || pdwReserved || dwFlags)
2078  {
2080  return FALSE;
2081  }
2082 
2083  *phHash = new_object(&handle_table, sizeof(CRYPTHASH), RSAENH_MAGIC_HASH,
2084  destroy_hash, (OBJECTHDR**)&pDestHash);
2085  if (*phHash != (HCRYPTHASH)INVALID_HANDLE_VALUE)
2086  {
2087  *pDestHash = *pSrcHash;
2088  duplicate_hash_impl(pSrcHash->aiAlgid, &pSrcHash->context, &pDestHash->context);
2089  copy_hmac_info(&pDestHash->pHMACInfo, pSrcHash->pHMACInfo);
2090  copy_data_blob(&pDestHash->tpPRFParams.blobLabel, &pSrcHash->tpPRFParams.blobLabel);
2091  copy_data_blob(&pDestHash->tpPRFParams.blobSeed, &pSrcHash->tpPRFParams.blobSeed);
2092  }
2093 
2094  return *phHash != (HCRYPTHASH)INVALID_HANDLE_VALUE;
2095 }
#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:72
CRYPT_DATA_BLOB blobSeed
Definition: rsaenh.c:61
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
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:572
static void destroy_hash(OBJECTHDR *pObject)
Definition: rsaenh.c:611
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:475
#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:74
#define SetLastError(x)
Definition: compat.h:409
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
CRYPT_DATA_BLOB blobLabel
Definition: rsaenh.c:60
_Reserved_ DWORD * pdwReserved
Definition: wincrypt.h:4254
ULONG_PTR HCRYPTHASH
Definition: wincrypt.h:50
RSAENH_TLS1PRF_PARAMS tpPRFParams
Definition: rsaenh.c:75
#define RSAENH_MAGIC_HASH
Definition: rsaenh.c:54
#define NTE_BAD_UID
Definition: winerror.h:2869
#define RSAENH_MAGIC_CONTAINER
Definition: rsaenh.c:125
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 2113 of file rsaenh.c.

2115 {
2116  CRYPTKEY *pSrcKey, *pDestKey;
2117 
2118  TRACE("(hUID=%08lx, hKey=%08lx, pdwReserved=%p, dwFlags=%08x, phKey=%p)\n", hUID, hKey,
2119  pdwReserved, dwFlags, phKey);
2120 
2122  {
2124  return FALSE;
2125  }
2126 
2127  if (!lookup_handle(&handle_table, hKey, RSAENH_MAGIC_KEY, (OBJECTHDR**)&pSrcKey))
2128  {
2130  return FALSE;
2131  }
2132 
2133  if (!phKey || pdwReserved || dwFlags)
2134  {
2136  return