Граф коммитов

78 Коммитов

Автор SHA1 Сообщение Дата
Samuel Lee 2b82f03465 Merged PR 11375621: Fix outstanding Prefast warnings
+ Fixing various Prefast warnings to get us clean w.r.t. Prefast
  + Enable Prefast failures to break PR builds
+ Reduce noisy build warnings
+ Unpin Windows container images as using old images

Related work items: #52514550, #52514551, #52514554, #52514555, #52514556, #52514557, #52514559, #52514560, #52514561, #52514562, #52514632, #52514633, #52514634, #53004108, #53004109, #53130817
2024-09-05 23:26:39 +00:00
Samuel Lee 977ec1e5f0 Merged PR 11273883: Implement ML-KEM
## Description:

+ Adds ML-KEM API surface
+ Implements the API with initial C implementation, with sprinkling of SSE/NEON for (I)NTT
+ Adds low level ML-KEM polynomial arithmetic testing which tests self-consistency and exercises internal assertion in debug builds
+ Adds multi-implementation functionality testing to enable comparative functionality and performance testing on E2E functionality
  + For now, comparison testing is just between SymCrypt static and dynamic, with 3rd party comparison with libcrux disabled until they publish a final ML-KEM implementation
+ Adds ML-KEM KATs from NIST

Related work items: #50913735
2024-08-31 02:53:41 +00:00
Mitch Lindgren 🦎 3b4cad7a6a Merged PR 11324214: FIPS 140-3 CASTs for RSA, DSA, ECDSA
This change adds additional Cryptographic Algorithm Self-Tests (CASTs) for RSA, DSA and ECDSA. as required by FIPS 140-3. Specifically, it adds explicit Known Answer Tests (KATs), as the Pairwise Consistency Tests (PCTs) that we were using previously are no longer considered sufficient for CASTs.

Also adds pairwise consistency tests on key import for RSA and DSA, per recent changes in the FIPS 140-3 implementation guidance. ECDSA PCTs continue to be run prior to signing or key export, as a performance optimization. ECDH and DH do not have explicit PCTs, but they include the required checks specified in SP 800-56A rev 3.

Related work items: #53481333
2024-08-30 05:26:38 +00:00
Cagdas Calik 15d0779214 Merged PR 10817310: Add XMSS and XMSS^MT implementations
## Description:

Adds support for stateful hash-based signatures XMSS and XMSS^MT per RFC 8391 and NIST SP800-208.

## Admin Checklist:
- [ ] You have updated documentation in symcrypt.h to reflect any changes in behavior
- [ ] You have updated CHANGELOG.md to reflect any changes in behavior
- [ ] You have updated symcryptunittest to exercise any new functionality
- [ ] If you have introduced any symbols in symcrypt.h you have updated production and test dynamic export symbols (exports.ver / exports.def / symcrypt.src) and tested the updated dynamic modules with symcryptunittest
- [ ] If you have introduced functionality that varies based on CPU features, you have manually tested with and without relevant features
- [ ] If you have made significant changes to a particular algorithm, you have checked that performance numbers reported by symcryptunittest are in line with expectations
- [ ] If you have added new algorithms/modes, you have updated the status indicator text for the associated modules if necessary

Related work items: #52453903
2024-08-13 18:14:13 +00:00
Maxwell Moyer-McKee f89cbf36c3 Merged PR 11087190: SSKDF implementation
## Description:
SSKDF implementation and unit tests.
 
## Admin Checklist:
- [x] You have updated documentation in symcrypt.h to reflect any changes in behavior
- [x] You have updated CHANGELOG.md to reflect any changes in behavior
- [x] You have updated symcryptunittest to exercise any new functionality
- [x] If you have introduced any symbols in symcrypt.h you have updated production and test dynamic export symbols (exports.ver / exports.def / symcrypt.src) and tested the updated dynamic modules with symcryptunittest
- [x] If you have introduced functionality that varies based on CPU features, you have manually tested with and without relevant features
- [X] If you have made significant changes to a particular algorithm, you have checked that performance numbers reported by symcryptunittest are in line with expectations
- [X] If you have added new algorithms/modes, you have updated the status indicator text for the associated modules if necessary

Related work items: #51795170
2024-08-12 22:55:13 +00:00
Maxwell Moyer-McKee ff2944eca8 Merged PR 10928970: SP800-56C (SSKDF) API
## Description:
- Adds prototype API for SP800-56C KDF (aka SSKDF)
- Updates the SYMCRYPT_MAC_STATE and SYMCRYPT_MAC_EXPANDED_KEY unions to include SHA3 based MACs.
  - If this was purposefully omitted from !8234403, I will revert the change, but the SymCryptSsMacKdf functions will need to be split.

## Admin Checklist:
- [X] You have updated documentation in symcrypt.h to reflect any changes in behavior
- [X] You have updated CHANGELOG.md to reflect any changes in behavior
- [X] You have updated symcryptunittest to exercise any new functionality
- [X] If you have introduced any symbols in symcrypt.h you have updated production and test dynamic export symbols (exports.ver / exports.def / symcrypt.src) and tested the updated dynamic modules with symcryptunittest
- [X] If you have introduced functionality that varies based on CPU features, you have manually tested with and without relevant features
- [X] If you have made significant changes to a particular algorithm, you have checked that performance numbers reported by symcryptunittest are in line with expectations
- [X] If you have added new algorithms/modes, you have updated the status indicator text for the associated modules if necessary

Related work items: #51795162
2024-07-12 16:57:38 +00:00
Mitch Lindgren 🦎 198be4c6b7 Merged PR 10493895: Add Windows user mode module
This change adds a new Windows user-mode module, symcrypt.dll. We plan to integrate this module into a future release of Windows as our primary FIPS-certified cryptographic module. Until that happens, we're making the module publicly available for the convenience of other projects that build on top of SymCrypt, such as our [rust-symcrypt crate](https://github.com/microsoft/rust-symcrypt).

Tested: dynamic unit tests run locally against the new module, ADO pipeline CI tests
2024-03-30 01:10:14 +00:00
Shachar Levy 476b8382f0 Merged PR 10172292: Add symcrypt build for optee env
## Description:

## Admin Checklist:
- [ ] You have updated documentation in symcrypt.h to reflect any changes in behavior
- [ ] You have updated CHANGELOG.md to reflect any changes in behavior
- [ ] You have updated symcryptunittest to exercise any new functionality
- [ ] If you have introduced any symbols in symcrypt.h you have updated production and test dynamic export symbols (exports.ver / exports.def / symcrypt.src) and tested the updated dynamic modules with symcryptunittest
- [ ] If you have introduced functionality that varies based on CPU features, you have manually tested with and without relevant features
- [ ] If you have made significant changes to a particular algorithm, you have checked that performance numbers reported by symcryptunittest are in line with expectations
- [ ] If you have added new algorithms/modes, you have updated the status indicator text for the associated modules if necessary

Add symcrypt build for optee env

Signed-off-by: v-shlevy <v-shlevy@microsoft.com>

Related work items: #49419416
2024-03-28 00:00:31 +00:00
Mitch Lindgren 🦎 a84ffe1146 Merged PR 10177217: Remove outdated security advice on RC4 comment
Per [this GitHub issue](https://github.com/microsoft/SymCrypt/issues/34), the advice on key generation for RC4 is outdated and no longer best practice. RC4 should never be used except for backwards compatibility, but this part of the comment is unhelpful in any case, so this PR removes it.

Thanks to [Myriachan](https://github.com/Myriachan) for reporting this issue.
2024-01-27 06:00:47 +00:00
Mitch Lindgren 🦎 d6933e03f6 Merged PR 9746161: Support cbNonce != 12 for AES-GCM
This change adds support for nonces larger or smaller than 12-bytes for AES-GCM (and GCM generally, if it's ever used with other block ciphers). It adds 32-bit CTR functions, as required in the GCM spec. Previously we used a 64-bit CTR function, which worked for 12-byte nonces because the counter block always started at 1 and the message length limit for GCM is 2^36 - 32 bytes, so the 32-bit counter would never overflow. Using a 64-bit counter does not work for non-12-byte nonces because the counter block starts at an arbitrary value computed by GHASHing the nonce.

It also updates the "stitched" implementations of AES-GCM to use 32-bit addition intrinsics instead of 64-bit addition.

Tested with unit tests:
- AMD64 with all features enabled
- AMD64 without aesni
- AMD64 without pclmulqdq
- AMD64 with everything disabled except for rdrand, rdseed, savexmmnofail
- ARM64 hardware (Galaxy Book 2) + qemu (via pipeline)

Related work items: #33824154
2023-10-31 22:21:18 +00:00
Samuel Lee ffbb5939a3 Merged PR 9759115: Adding support for salt length detection in RSA-PSS verification
Adding support for salt length detection in RSA-PSS verification

+ Add SYMCRYPT_FLAG_RSA_PSS_VERIFY_WITH_MINIMUM_SALT flag to
  SymCryptRsaPssVerify and SymCryptRsaPssVerifySignaturePadding
+ When verifying a PSS signature with this flag specified, allow salt
  length >= the caller specified cbSalt
+ In symcryptunittest, test that verification succeeds and fails w.r.t. the cbSalt
 and flag in the correct way
+ Some small unrelated changes

Related work items: #33692439
2023-10-27 22:46:31 +00:00
Samuel Lee 4425e78d9d Merged PR 9685563: Extend XTS-AES for SCOSSL and SymCrypt FIPS
+ Add SymCryptXtsAes(En|De)cryptEx to induce XTS-AES with 128b tweak
+ Add SymCryptXtsAesExpandKeyEx to do FIPS IG check for non-equal
 halves of XTS key
+ Refactor Multi-DataUnit logic to reduce code duplication using
 new xtsaes_pattern.c file to instantiate the logic with various
 specializations
+ Add support for ciphertext stealing in both old and new API surface,
  allowing data unit sizes which are not a multiple of 16 bytes
+ Add IEEE test vectors for odd data unit sizes
+ Update randomized tests to exercise both 64-bit and 128-bit tweak
  interfaces, and new supported data unit sizes
+ Update XTS tests to allow CNG to fail with unsupported parameters
+ Update XTS FIPS self-test to use FIPS-approved key expansion function
+ Fix a couple of typos found while making changes

Related work items: #43854713
2023-10-19 23:17:23 +00:00
Samuel Lee d9e29fad97 Merged PR 8830926: Update symcrypt.h to make caller responsibility on Fatal errors explicit 2023-04-17 23:22:29 +00:00
Samuel Lee 770f81ffb4 Merged PR 8777064: Fixes for various clang x86 errors / warnings
+ Specify void argument for C functions with no parameters
+ Enable -Wstrict-prototypes to prevent regression
+ Do not rely on __m128i struct definition
+ Fixup fastcall attribute
+ Fixup alignment attribute for union and struct typedefs which were
  previously missed
+ Quash warnings about tautological comparisons with size_t and constant
  values larger than 32b by including explicitly constant compile time
  comparisons
+ Enable clang x86 build in ADO pipeline

Related work items: #44081913
2023-04-07 20:54:01 +00:00
Cagdas Calik ef2e54a42d Merged PR 8399946: Add HMAC support for SHA-3
Add HMAC-SHA3-256, HMAC-SHA3-384, HMAC-SHA3-512 implementations.

Other changes:
- Add generic HMAC API
- Introduce a unique state for each of the Keccak based algorithms
- Convert tabs to spaces in symcryptasm files

Related work items: #41559779
2023-01-26 01:04:50 +00:00
Cagdas Calik d026121894 Merged PR 8234403: Add SHA-3 based algorithms: SHAKE, cSHAKE, and KMAC
This PR adds the following algorithm implementations to SymCrypt:
- Extendable-output functions (XOFs)
  - SHAKE128
  - SHAKE256
- Customizable XOFs
  - cSHAKE128
  - cSHAKE256
- Keccak Message Authentication Code (KMAC)
  - KMAC128
  - KMAC256

Related work items: #41559779
2023-01-17 23:54:37 +00:00
Samuel Lee b8a005237c Merged PR 8152559: Introduce SymCryptKernelTestModule
+ New dynamic module SymCryptKernelTestModule_UM.dll and kernel driver
  SymCryptKernelTestModule.sys which enable unit tests to call into
  driver using the existing SymCrypt dynamic module flow
+ Update a few places in tests which assume objects created by module
  under test can have their internals inspected (which is not the case
  when the object lives in kernel and the unit tests are running in user
  mode)
+ SymCryptKernelTestModule.sys tracks all allocations it makes and ensures it
 frees everything when it is unloaded

Related work items: #38706387
2022-12-16 22:58:09 +00:00
Samuel Lee 07a5bf94d0 Merged PR 8176148: Linux RNG perf testing and improvements
+ Enable measurements of Linux RNG system
+ Make various performance improvements to defer costly calls into JitterEntropy until they are strictly required,
and reduce cost of calls when they are made.

Related work items: #42441472, #42441492
2022-12-02 20:11:46 +00:00
Cagdas Calik 93a82712df Merged PR 7979179: Add SHA-3 implementations
This update adds C implementations of SHA-3-256, SHA-3-384, and SHA-3-512 hash functions per FIPS 202.

Related work items: #41559779
2022-10-25 20:39:41 +00:00
Cagdas Calik bc66c79cde Merged PR 7810991: Add SRTP-KDF and SSH-KDF implementations
- Add SRTP-KDF and SSH-KDF implementations
- Update `SYMCRYPT_HASH` structure to contain hash state copying function member

Related work items: #38101963, #38102026
2022-09-19 20:13:04 +00:00
Samuel Lee 317e785816 Merged PR 7349481: Avoid Unnecessary Pairwise Conditional Tests on (EC)DH key generation
+ Avoid Unnecessary Pairwise Conditional Tests on (EC)DH key generation
+ Enable deferred testing of PCTs for all asymmetric key generation
  + Introduce a new UINT32 field in the (Dl|Ec|Rsa)key structures to track what algorithms the key may be used for, and which key PCTs have been run
+ For ECDSA, perform PCT before first use of private key in an sign
  operation
+ For RSA and DSA, just perform the PCT unconditionally at key generation time
+ Remove the (EC)DH PCT functions entirely. They are not necessary for
  FIPS and no calling application should be using them as they were very
  recently introduced.
+ Fix corner case bug with DH and explicitly set private key lengths not having the correct validation.

Related work items: #37791870, #39478648
2022-05-25 19:51:34 +00:00
Samuel Lee cc344e4ac8 Merged PR 7272939: Return SYMCRYPT_SIGNATURE_VERIFICATION_FAILURE from SymCryptRsaPssVerify
+ Return SYMCRYPT_SIGNATURE_VERIFICATION_FAILURE from SymCryptRsaPssVerify
+ Also change tests to alias the error codes so that
  multi-implementation test with SymCrypt and CNG do not break while the
  change to SymCrypt rolls out.
+ BCrypt callers should already handle STATUS_INVALID_SIGNATURE as this
  is the error code that they should expect from documentation

Related work items: #39175561
2022-04-23 00:30:51 +00:00
Samuel Lee d70e7f5c1f Merged PR 7061228: AES-GCM session implementation
Add AES-GCM session implementation

+ The GCM encryption session implementation enables FIPS certification of AES-GCM as the nonce generation is within the FIPS boundary
+ The GCM decryption session enables replay protection for callers. It is designed to be useful for fresh a higher level protocol like QCC

Related work items: #38643032
2022-03-26 22:08:37 +00:00
Mitch Lindgren 🦎 ffe1a115ae Merged PR 7070461: Add self-tests for DL, ECC and RSA key generation
In addition to the algorithm self-tests that must be run once prior to each algorithm being used, FIPS 140-3 also requires pairwise consistency tests for all keys generated:

> “If a cryptographic module generates public or private key pairs, a pair-wise consistency test shall [10.35] be performed for every generated public and private key pair…”

This change implements these self-tests for DL, ECC and RSA keys.

Related work items: #38587829
2022-03-21 22:31:23 +00:00
Mitch Lindgren 🦎 d7e322ef75 Merged PR 6884452: Support proper shared object library versioning
- Moved shared CMake logic into a single common file that can be included from individual module directories.
- Renamed some directories to hopefully make the directory structure more logical.
- Updated CMake commands to include appropriate versioning info in modules. This causes CMake to automatically build the module with a versioned shared object name (libsymcrypt.so -> libsymcrypt.so.100 -> libsymcrypt.so.100.21.0). The appropriate SONAME is also set in the module's DYNAMIC section, so that applications or modules taking a dependency on us will correctly link to libsymcrypt.so.100.
2022-01-28 19:20:57 +00:00
Samuel Lee 5b03aac5c7 Merged PR 6708039: Add SymCryptHkdfExtractPrk API
+ The definition of HKDF as two steps in RFC 5869 is slightly different
  to the two steps currently implemented in SymCrypt
  + In the RFC the pseudorandom key (PRK) is defined as the output of
    HKDF-Extract, and an input to HKDF-Expand
  + In SymCrypt we currently merge the use of the PRK to create an
    expanded HMAC key into the HkdfExpandKey function, so a caller never
    sees the generated PRK with the current API
+ So that we can use SymCrypt for callers which expose the RFC's steps
  more rigidly we need to introduce a new function: `SymCryptHkdfExtractPrk`
+ This allows callers to handle the PRK produced by the HKDF-Extract
  step explicitly
+ The underlying implementation is slightly refactored for this new API,
  with HkdfExpandKey calling HkdfExtractPrk then HkdfPrkExpandKey, using
  a stack buffer to store the temporary PRK. The functionality is
  otherwise unchanged
+ The 3 ways to perform HKDF end to end with SymCrypt are now:
  a) HkdfExtractPrk -> HkdfPrkExpandKey -> HkdfDerive
  b) HkdfExpandKey  -> HkdfDerive
  c) Hkdf

Related work items: #37166888
2021-12-09 15:09:19 +00:00
Samuel Lee c76ef864db Merged PR 6707894: Add SP800-108 self tests for HmacSha512 and tidy up KDF self tests
+ KMAN uses SP800-108 with HmacSha512 - we will need to certify this in the SymCrypt module for Overlake / Mariner, so add SelfTests for this combination.
+ Also tidy up some comments which are clearly copy-paste errors
+ Ignore build artifacts that are in the jitterentropy submodule

Related work items: #37166368
2021-12-09 13:05:29 +00:00
Samuel Lee 96b239866f Add SymCryptHkdfExtractPrk API
+ The definition of HKDF as two steps in RFC 5869 is slightly different
  to the two steps currently implemented in SymCrypt
  + In the RFC the pseudorandom key (PRK) is defined as the output of
    HKDF-Extract, and an input to HKDF-Expand
  + In SymCrypt we currently merge the use of the PRK to create an
    expanded HMAC key into the HkdfExpandKey function, so a caller never
    sees the generated PRK with the current API
+ So that we can use SymCrypt for callers which expose the RFC's steps
  more rigidly we need to introduce a new function: `SymCryptHkdfExtractPrk`
+ This allows callers to handle the PRK produced by the HKDF-Extract
  step explicitly
+ The underlying implementation is slightly refactored for this new API,
  with HkdfExpandKey calling HkdfExtractPrk then HkdfPrkExpandKey, using
  a stack buffer to store the temporary PRK. The functionality is
  otherwise unchanged
+ The 3 ways to perform HKDF end to end with SymCrypt are now:
  a) HkdfExtractPrk -> HkdfPrkExpandKey -> HkdfDerive
  b) HkdfExpandKey  -> HkdfDerive
  c) Hkdf
2021-12-09 04:30:10 -08:00
Samuel Lee 1db382eadf Add SymCryptDlkeySetPrivateKeyLength API
+ Move nBitsPriv to be on a per-Dlkey basis, with fields in the Dlgroup
  informing the range it can take and setting a default value to avoid
  changes for existing callers
+ Use the new API in a new test case - still have to write a more
  involved test case using SymCryptDlkeySetValue as well
2021-11-26 09:31:28 -08:00
Samuel Lee 52e04d95e0 Add SP800-108 self tests for HmacSHA512 and tidy up KDF self tests 2021-11-26 05:51:22 -08:00
Samuel Lee 2cba13943d Merged PR 6703946: SymCryptDlgroupSetValueSafePrime: Remove redundant pDlgroup check for NULL
Related work items: #37128890
2021-11-26 13:30:26 +00:00
Samuel Lee 347c4dd1a0 Remove NULL check for pDlgroup for consistency with other SetValue API
+ Callers would invariably check for NULL after Allocate / Create
  anyway, so this would be a duplicate check
+ Also resolve some nitpick issues in build for razzle / build with
  Linux with jitterentropy
2021-11-26 04:56:03 -08:00
Samuel Lee a5bd66084b Merged PR 6558632: Address the vast majority of other SymCryptFatals
+ In some cases replace with C_ASSERTs
+ In some cases replace with SYMCRYPT_ASSERTs (fail only in CHK build)
+ In some cases replace with SYMCRYPT_ASSERT and replace a faulty input
  with an input which will give a result which is incorrect but won't
  crash

Related work items: #37153656, #35463330
2021-11-25 11:13:43 +00:00
Spencer Nofzinger e21acd0b57 Merged PR 6578055: Added mariner and overlake modules. Generalized RNG functions. Implemented en...
Added embedded modules. Generalized RNG functions. Added Jitter as submodule and implemented entropy sourcing from Jitter for embedded and generic Linux modules

Related work items: #36787279
2021-11-18 21:42:39 +00:00
Samuel Lee b12b94cdfc Merged PR 6495483: Merge symcrypt_debug.inc and symcrypt_version.inc
+ SYMCRYPT_DEBUG is only defined in the C preprocessor for assembly,
  ensure that it is set up correctly in assembly by defining DBG in the
  USER_C_FLAGS in a non-release build
2021-09-23 19:06:53 +00:00
Samuel Lee 0e232d4392 Merged PR 6315721: OACR fixups
+ Resolves all issues flagged by runoacr in symcrypt\lib
  + Leaves some oacr issues in test code
+ Also includes some unrelated fixes to typos etc.

Related work items: #35052770
2021-08-04 15:18:36 +00:00
Yuval Harpaz 2839a6d144 Adding Add/Remove Padding for PKCS7 2021-07-21 20:32:40 +03:00
Yuval Harpaz 6a765350ce Merge branch 'master' into yuvalharpaz-paddingPkcs7 2021-07-11 10:28:22 +03:00
Samuel Lee 7506893113 Merged PR 6215627: Small bug fixes 2021/07/01
+ Fix SYMCRYPT_INTERNAL_LOAD_LSBFIRST32 macro for generic build
+ Re-enable generic build in the pipeline
  + Only trigger for CI builds normally to avoid blocking PRs needlessly
  + Also trigger on PR builds to publish branch, to catch any regression we may not have noticed before publishing to GitHub
+ Fix a bunch of non-functional typos that I have noticed recently
+ Only run the module test when the task is running on a machine with RDSEED - the module test currently requires RDSEED.

Related work items: #34245222
2021-07-08 19:21:24 +00:00
Yuval Harpaz 5707111a68 Adding Add/Remove Padding for PKCS7 2021-07-06 20:20:23 +03:00
Yuval Harpaz 8f7475ff45 Adding Add/Remove Padding for PKCS7 2021-06-29 09:09:50 +03:00
Yuval Harpaz cc8921862f Adding Add/Remove Padding for PKCS7 2021-06-28 13:51:38 +03:00
Yuval Harpaz 5a0a87a6f2 Adding Add/Remove Padding for PKCS7 2021-06-28 09:53:52 +03:00
Yuval Harpaz 1a92008ab7 Adding Add/Remove Padding for PKCS7 2021-06-24 22:12:48 +03:00
Mitch Lindgren a3c69b1531 Addressed more comments, cleanup 2021-06-15 17:04:10 -07:00
Mitch Lindgren c61dc63cad Addressed comments 2021-06-14 23:44:05 -07:00
Mitch Lindgren 53639a04d4 Changed RSA test to use hardcoded key 2021-06-14 18:16:09 -07:00
Mitch Lindgren a1a605d059 Added calls into other selftests from respective keygen functions 2021-06-13 23:35:49 -07:00
Mitch Lindgren 18049cb8e3 Changed DH/ECDH tests back to calling fatal on failure. Made ECDH test use hardcoded keys. 2021-06-13 18:23:18 -07:00
Mitch Lindgren e31b89e584 Add spectre mitigation flag. Fix DH secret agreement test. 2021-06-13 16:27:13 -07:00