Skip to content

Commit 6d37d53

Browse files
committed
Merged PR 13588380: Add accessor functions for extern const data symbols
Exporting data symbols from a dynamic module makes linking complicated on Windows. It requires the headers to define the symbols as `__declspec(dllimport)` only on the consuming side, which requires either two separate headers, or special macros. Without `declspec(dllimport)` the linker will not be able to find the data symbols. This has tripped up a number of consumers. Providing accessor functions alleviates this issue, and is better practice for a dynamic library anyway, because it provides better ABI stability and encapsulation. Background: - [Import into an application using __declspec(dllimport)](https://learn.microsoft.com/en-us/cpp/build/importing-into-an-application-using-declspec-dllimport?view=msvc-170) - [LNK4217 - Russ Keldorph's WebLog - Site Home - MSDN Blogs (archive.org)](https://web.archive.org/web/20140911111411/http://blogs.msdn.com/b/russellk/archive/2005/03/20/399465.aspx?wa=wsignin1.0) Related work items: #52850075
1 parent 207e74d commit 6d37d53

24 files changed

+883
-184
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
New changes will be listed here as they are developed. The version number is determined
44
prior to the creation of a new release, based on the changes contained in that release.
55

6+
# Version 103.10.0
7+
8+
- Fixed [#51](https://github.com/microsoft/SymCrypt/issues/51): Added accessor functions for `extern const` data symbols to prevent error `LNK2001` when dynamic linking on Windows
9+
610
# Version 103.9.1
711

12+
- Fixed [#48](https://github.com/microsoft/SymCrypt/issues/48): Fix minor interop issue in RSA PKCS1
813
- Removed dependency on external randomness in ECDSA self-test
9-
- Fix minor interop issue in RSA PKCS1
1014
- Add FIPS CAST for ML-DSA and pairwise consistency tests for ML-KEM and ML-DSA on key generation
1115

1216
# Version 103.9.0

inc/symcrypt.h

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,35 @@ SymCryptEqual(
764764
// signature verification library.
765765
//
766766

767+
typedef enum _SYMCRYPT_HASH_ID
768+
{
769+
SYMCRYPT_HASH_ID_NULL = 0,
770+
SYMCRYPT_HASH_ID_MD2 = 1,
771+
SYMCRYPT_HASH_ID_MD4 = 2,
772+
SYMCRYPT_HASH_ID_MD5 = 3,
773+
SYMCRYPT_HASH_ID_SHA1 = 4,
774+
SYMCRYPT_HASH_ID_SHA224 = 5,
775+
SYMCRYPT_HASH_ID_SHA256 = 6,
776+
SYMCRYPT_HASH_ID_SHA384 = 7,
777+
SYMCRYPT_HASH_ID_SHA512 = 8,
778+
SYMCRYPT_HASH_ID_SHA512_224 = 9,
779+
SYMCRYPT_HASH_ID_SHA512_256 = 10,
780+
SYMCRYPT_HASH_ID_SHA3_224 = 11,
781+
SYMCRYPT_HASH_ID_SHA3_256 = 12,
782+
SYMCRYPT_HASH_ID_SHA3_384 = 13,
783+
SYMCRYPT_HASH_ID_SHA3_512 = 14,
784+
SYMCRYPT_HASH_ID_SHAKE128 = 15,
785+
SYMCRYPT_HASH_ID_SHAKE256 = 16
786+
} SYMCRYPT_HASH_ID;
787+
788+
PCSYMCRYPT_HASH
789+
SYMCRYPT_CALL
790+
SymCryptGetHashAlgorithm( SYMCRYPT_HASH_ID hashId );
791+
//
792+
// Returns a pointer to the hash algorithm structure for the specified hash ID.
793+
// Returns NULL if the hash ID is invalid.
794+
//
795+
767796
SIZE_T
768797
SYMCRYPT_CALL
769798
SymCryptHashResultSize( _In_ PCSYMCRYPT_HASH pHash );
@@ -2540,6 +2569,33 @@ SymCryptParallelSha512Selftest(void);
25402569
// computation can be selected at runtime.
25412570
//
25422571

2572+
typedef enum _SYMCRYPT_MAC_ID
2573+
{
2574+
SYMCRYPT_MAC_ID_NULL = 0,
2575+
SYMCRYPT_MAC_ID_HMAC_MD5 = 1,
2576+
SYMCRYPT_MAC_ID_HMAC_SHA1 = 2,
2577+
SYMCRYPT_MAC_ID_HMAC_SHA224 = 3,
2578+
SYMCRYPT_MAC_ID_HMAC_SHA256 = 4,
2579+
SYMCRYPT_MAC_ID_HMAC_SHA384 = 5,
2580+
SYMCRYPT_MAC_ID_HMAC_SHA512 = 6,
2581+
SYMCRYPT_MAC_ID_HMAC_SHA512_224 = 7,
2582+
SYMCRYPT_MAC_ID_HMAC_SHA512_256 = 8,
2583+
SYMCRYPT_MAC_ID_HMAC_SHA3_224 = 9,
2584+
SYMCRYPT_MAC_ID_HMAC_SHA3_256 = 10,
2585+
SYMCRYPT_MAC_ID_HMAC_SHA3_384 = 11,
2586+
SYMCRYPT_MAC_ID_HMAC_SHA3_512 = 12,
2587+
SYMCRYPT_MAC_ID_AES_CMAC = 13,
2588+
SYMCRYPT_MAC_ID_KMAC_128 = 14,
2589+
SYMCRYPT_MAC_ID_KMAC_256 = 15
2590+
} SYMCRYPT_MAC_ID;
2591+
2592+
PCSYMCRYPT_MAC
2593+
SYMCRYPT_CALL
2594+
SymCryptGetMacAlgorithm( SYMCRYPT_MAC_ID macId );
2595+
//
2596+
// Returns a pointer to the MAC algorithm structure for the specified MAC ID.
2597+
// Returns NULL if the MAC ID is invalid.
2598+
//
25432599

25442600
//
25452601
// Generic HMAC API with parametrized hash function
@@ -3948,6 +4004,13 @@ SymCryptMarvin32ExpandSeed(
39484004

39494005
extern PCSYMCRYPT_MARVIN32_EXPANDED_SEED const SymCryptMarvin32DefaultSeed;
39504006

4007+
PCSYMCRYPT_MARVIN32_EXPANDED_SEED
4008+
SYMCRYPT_CALL
4009+
SymCryptGetMarvin32DefaultSeed( void );
4010+
//
4011+
// Returns a pointer to the default Marvin32 seed.
4012+
//
4013+
39514014
VOID
39524015
SYMCRYPT_CALL
39534016
SymCryptMarvin32SeedCopy( _In_ PCSYMCRYPT_MARVIN32_EXPANDED_SEED pSrc,
@@ -4552,6 +4615,24 @@ extern const PCSYMCRYPT_BLOCKCIPHER SymCryptRc2BlockCipher;
45524615
// (The SYMCRYPT_BLOCKCIPHER structure is a private one not available to callers.)
45534616
//
45544617

4618+
typedef enum _SYMCRYPT_BLOCKCIPHER_ID
4619+
{
4620+
SYMCRYPT_BLOCKCIPHER_ID_NULL = 0,
4621+
SYMCRYPT_BLOCKCIPHER_ID_AES = 1,
4622+
SYMCRYPT_BLOCKCIPHER_ID_DES = 2,
4623+
SYMCRYPT_BLOCKCIPHER_ID_3DES = 3,
4624+
SYMCRYPT_BLOCKCIPHER_ID_DESX = 4,
4625+
SYMCRYPT_BLOCKCIPHER_ID_RC2 = 5
4626+
} SYMCRYPT_BLOCKCIPHER_ID;
4627+
4628+
PCSYMCRYPT_BLOCKCIPHER
4629+
SYMCRYPT_CALL
4630+
SymCryptGetBlockCipher( SYMCRYPT_BLOCKCIPHER_ID blockCipherId );
4631+
//
4632+
// Returns a pointer to the block cipher structure for the specified block cipher ID.
4633+
// Returns NULL if the block cipher ID is invalid.
4634+
//
4635+
45554636
VOID
45564637
SYMCRYPT_CALL
45574638
SymCryptEcbEncrypt(
@@ -8213,6 +8294,28 @@ extern const PCSYMCRYPT_ECURVE_PARAMS SymCryptEcurveParamsNumsP512t1;
82138294

82148295
extern const PCSYMCRYPT_ECURVE_PARAMS SymCryptEcurveParamsCurve25519;
82158296

8297+
typedef enum _SYMCRYPT_ECURVE_ID
8298+
{
8299+
SYMCRYPT_ECURVE_ID_NULL = 0,
8300+
SYMCRYPT_ECURVE_ID_NIST_P192 = 1,
8301+
SYMCRYPT_ECURVE_ID_NIST_P224 = 2,
8302+
SYMCRYPT_ECURVE_ID_NIST_P256 = 3,
8303+
SYMCRYPT_ECURVE_ID_NIST_P384 = 4,
8304+
SYMCRYPT_ECURVE_ID_NIST_P521 = 5,
8305+
SYMCRYPT_ECURVE_ID_NUMS_P256T1 = 6,
8306+
SYMCRYPT_ECURVE_ID_NUMS_P384T1 = 7,
8307+
SYMCRYPT_ECURVE_ID_NUMS_P512T1 = 8,
8308+
SYMCRYPT_ECURVE_ID_CURVE25519 = 9
8309+
} SYMCRYPT_ECURVE_ID;
8310+
8311+
PCSYMCRYPT_ECURVE_PARAMS
8312+
SYMCRYPT_CALL
8313+
SymCryptGetEcurveParams( SYMCRYPT_ECURVE_ID ecurveId );
8314+
//
8315+
// Returns a pointer to the elliptic curve parameters structure for the specified curve ID.
8316+
// Returns NULL if the curve ID is invalid.
8317+
//
8318+
82168319
//=====================================================
82178320
// ECC flags
82188321
//

inc/symcrypt_internal.h

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,15 +1097,15 @@ extern const SYMCRYPT_OID SymCryptSha256OidList[SYMCRYPT_SHA256_OID_COUNT];
10971097
#define SYMCRYPT_SHA384_OID_COUNT (2)
10981098
extern const SYMCRYPT_OID SymCryptSha384OidList[SYMCRYPT_SHA384_OID_COUNT];
10991099

1100+
#define SYMCRYPT_SHA512_OID_COUNT (2)
1101+
extern const SYMCRYPT_OID SymCryptSha512OidList[SYMCRYPT_SHA512_OID_COUNT];
1102+
11001103
#define SYMCRYPT_SHA512_224_OID_COUNT (2)
11011104
extern const SYMCRYPT_OID SymCryptSha512_224OidList[SYMCRYPT_SHA512_224_OID_COUNT];
11021105

11031106
#define SYMCRYPT_SHA512_256_OID_COUNT (2)
11041107
extern const SYMCRYPT_OID SymCryptSha512_256OidList[SYMCRYPT_SHA512_256_OID_COUNT];
11051108

1106-
#define SYMCRYPT_SHA512_OID_COUNT (2)
1107-
extern const SYMCRYPT_OID SymCryptSha512OidList[SYMCRYPT_SHA512_OID_COUNT];
1108-
11091109
#define SYMCRYPT_SHA3_224_OID_COUNT (2)
11101110
extern const SYMCRYPT_OID SymCryptSha3_224OidList[SYMCRYPT_SHA3_224_OID_COUNT];
11111111

@@ -1124,6 +1124,34 @@ extern const SYMCRYPT_OID SymCryptShake128OidList[SYMCRYPT_SHAKE128_OID_COUNT];
11241124
#define SYMCRYPT_SHAKE256_OID_COUNT (2)
11251125
extern const SYMCRYPT_OID SymCryptShake256OidList[SYMCRYPT_SHAKE256_OID_COUNT];
11261126

1127+
typedef enum _SYMCRYPT_OID_LIST_ID
1128+
{
1129+
SYMCRYPT_OID_LIST_ID_NULL = 0,
1130+
SYMCRYPT_OID_LIST_ID_MD5 = 1,
1131+
SYMCRYPT_OID_LIST_ID_SHA1 = 2,
1132+
SYMCRYPT_OID_LIST_ID_SHA224 = 3,
1133+
SYMCRYPT_OID_LIST_ID_SHA256 = 4,
1134+
SYMCRYPT_OID_LIST_ID_SHA384 = 5,
1135+
SYMCRYPT_OID_LIST_ID_SHA512 = 6,
1136+
SYMCRYPT_OID_LIST_ID_SHA512_224 = 7,
1137+
SYMCRYPT_OID_LIST_ID_SHA512_256 = 8,
1138+
SYMCRYPT_OID_LIST_ID_SHA3_224 = 9,
1139+
SYMCRYPT_OID_LIST_ID_SHA3_256 = 10,
1140+
SYMCRYPT_OID_LIST_ID_SHA3_384 = 11,
1141+
SYMCRYPT_OID_LIST_ID_SHA3_512 = 12,
1142+
SYMCRYPT_OID_LIST_ID_SHAKE128 = 13,
1143+
SYMCRYPT_OID_LIST_ID_SHAKE256 = 14
1144+
} SYMCRYPT_OID_LIST_ID;
1145+
1146+
PCSYMCRYPT_OID
1147+
SYMCRYPT_CALL
1148+
SymCryptGetOidList( SYMCRYPT_OID_LIST_ID oidId, _Out_opt_ SIZE_T* pCount );
1149+
//
1150+
// Returns a pointer to the OID list for the specified OID list ID. If pCount is non-NULL, the
1151+
// pointed-to value will be set to the number of elements in the OID list.
1152+
// Returns NULL if the OID list ID is invalid.
1153+
//
1154+
11271155
typedef union _SYMCRYPT_HASH_STATE
11281156
{
11291157
SYMCRYPT_MD2_STATE md2State;

lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ set(SOURCES_COMMON
2222
cpuid_um.c
2323
cpuid.c
2424
crt.c
25+
data_accessors.c
2526
DesTables.c
2627
desx.c
2728
dh.c

0 commit comments

Comments
 (0)