285 Commits

Author SHA1 Message Date
Tony Arcieri
1d1037b912
Initial proptests (#326)
Adds proptests for RSASSA-PKCS1-v1_5.

Includes a commented-out test for RSASSA-PSS which is currently failing.
2023-05-03 18:50:04 -06:00
Tony Arcieri
53bb256451
Left pad signatures when encoding (#325)
The `SignatureEncoding` impl added in `rsa` v0.9 (or more specifically,
the `From<Signature>` impl for `Box<[u8]>` failed to properly left pad
the signatures so they matched the modulus size.

This adds the appropriate padding to the signature encoder.
2023-05-03 18:34:50 -06:00
Tony Arcieri
94856ec765
pkcs1v15: note RSASSA-PKCS1-v1_5 in docs (#324)
This is the name for PKCS#1v1.5 signatures originally specified in
RFC3447 but is also used by RFC8017 (which we cite)
2023-05-03 17:13:52 -06:00
dependabot[bot]
901765df7c
build(deps): bump sha3 from 0.10.6 to 0.10.7 (#321)
Bumps [sha3](https://github.com/RustCrypto/hashes) from 0.10.6 to 0.10.7.
- [Release notes](https://github.com/RustCrypto/hashes/releases)
- [Commits](https://github.com/RustCrypto/hashes/compare/sha3-v0.10.6...sha3-v0.10.7)

---
updated-dependencies:
- dependency-name: sha3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-01 06:12:11 -06:00
dependabot[bot]
cbf6685c5e
build(deps): bump hex-literal from 0.3.4 to 0.4.1 (#319)
Bumps [hex-literal](https://github.com/RustCrypto/utils) from 0.3.4 to 0.4.1.
- [Release notes](https://github.com/RustCrypto/utils/releases)
- [Commits](https://github.com/RustCrypto/utils/compare/hex-literal-v0.3.4...hex-literal-v0.4.1)

---
updated-dependencies:
- dependency-name: hex-literal
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-01 06:11:58 -06:00
dependabot[bot]
f63290f920
build(deps): bump signature from 2.0.0 to 2.1.0 (#320)
Bumps [signature](https://github.com/RustCrypto/traits) from 2.0.0 to 2.1.0.
- [Release notes](https://github.com/RustCrypto/traits/releases)
- [Commits](https://github.com/RustCrypto/traits/compare/signature/v2.0.0...signature-v2.1.0)

---
updated-dependencies:
- dependency-name: signature
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-01 06:11:20 -06:00
Tony Arcieri
c611408a2e
v0.9.0 (#318) 2023-04-27 12:57:20 -06:00
Tony Arcieri
ec499565f9
Replace Deref impl on RsaPrivateKey with AsRef (#317)
The `RsaPrivateKey` type previously had a `Deref` impl providing access
to the associated `RsaPublicKey`.

`Deref` is intended for "smart pointer types", i.e. container types
which manage a (typically generic) inner type in some way. This doesn't
seem like one of those cases.

`AsRef`, on the other hand, is for cheap reference conversions, which is
exactly what's happening here, so it's a better fit and provides the
same functionality (albeit explicitly rather than via deref coercion).
2023-04-27 09:23:58 -06:00
Tony Arcieri
db2559faa7
Add comments to fields of RsaPublicKey (#316) 2023-04-27 08:23:41 -06:00
Tony Arcieri
f5918ad3bf
Refactor padding modes into submodules (#312)
The padding mode modules have gotten quite large.

This commit refactors types into respective submodules, with the
toplevel module defining the same-named padding schemes.
2023-04-27 07:58:19 -06:00
Tony Arcieri
d9968bc0c9
Refactor traits (#315)
There were several modules that defined traits, including one called
`traits`.

This consolidates all of them under `traits`, retaining the previous
module structure as internal submodules:

- `keytraits` => `traits::keys`
- `padding` => `traits::padding`
- `traits` => `traits::encryption`

Additionally this removes the traits that were re-exported at the
toplevel, instead re-exporting them all under `traits`.
2023-04-27 07:39:37 -06:00
Tony Arcieri
a8bddc2f6b
Add u64_digit feature (#313)
Adds an on-by-default feature which enables `num-bigint-dig/u64_digit`.

Disabling this on 32-bit platforms (e.g. WASM) should improve
performance.

Closes #252
2023-04-27 07:39:25 -06:00
Tony Arcieri
6d915b30f8
Rename CRTValue => CrtValue (#314)
Follows RFC430 (C-CASE)

https://rust-lang.github.io/api-guidelines/naming.html
2023-04-26 20:26:44 -06:00
Tony Arcieri
78ea9cb7da
Impl ZeroizeOnDrop for RsaPrivateKey+newtypes (#311)
`RsaPrivateKey` self-zeroizes on drop, so add the `ZeroizeOnDrop` marker
trait to `RsaPrivateKey` and all newtypes thereof, i.e. `DecryptingKey`
and `SigningKey` for the various padding modes.

This also removes the `Zeroize` impl on `RsaPrivateKey`, since it
self-zeroizes on `Drop`, and allowing `Zeroize` might accidentally
permit use-after-zeroize vulnerabilities.
2023-04-26 10:39:18 -06:00
Tony Arcieri
b1151dfb0e
v0.9.0-rc.0 (#309) 2023-04-25 08:48:24 -06:00
Tony Arcieri
c012868118
Impl core:#️⃣:Hash for RsaPrivateKey (#308)
Adds an impl which hashes only the public key components, along with a
domain separator string (`RsaPrivateKey`).

Closes #165
2023-04-25 08:37:01 -06:00
Tony Arcieri
faabaa7141
Improved public key checks (#307)
Adds the following checks:

- `n` is odd
- `e` is odd
- `e` < `n`

Closes #99
2023-04-25 08:36:46 -06:00
Tony Arcieri
b55c75ec39
Ensure signatures have right length and don't overflow (#306)
In both the PKCS#1v1.5 and PSS implementations, checks the signature
value to ensure it does not overflow the modulus.

In the PKCS#1v1.5 implementation, checks the signature length to ensure
it matches the public key size. The PSS implementation was already doing
this.

Closes #272
2023-04-25 08:36:26 -06:00
Tony Arcieri
bd14ee90b6
Bump pkcs1 dependency to v0.7.5 (#305)
Workaround for RustCrypto/formats#1021
2023-04-24 13:43:49 -06:00
Tony Arcieri
924ccfade5 Add SECURITY.md 2023-04-23 19:53:07 -06:00
Dmitry Baryshkov
574664808d
Internals refactoring (#304)
* feat: decouple key generation and random generation

Make generate_multi_prime_key_with_exp() generic enough to generate
abstract key structure. Rewrite RsaPrivateKey constructors to use
RsaPrivateKey::from_components().

* feat: move key-related traits to separate module

Move PublicKeyParts to the separate module.

* feat: stop using RsaPrivateKey in internals.rs

Make internals.rs generic enough to be moved to the algorithms module.

* feat: move soft RSA implementation to crate::algorithms::rsa.rs

Separate software RSA implementation to separate module under
crate::algorithms.

* key: drop raw_int_*_primitive wrappers

Now as raw_int_encryption_primitive() and raw_int_decryption_primitive()
became simple wrappers around properly defined functions we can inline
them and always use software RSA algorithm from src::algorithms::rsa.rs.

* feat: move internals.rs to src/algortihms/pad.rs

internals.rs now contains only small functions related to BigUint to
Vec<u8> conversion. Move them to src/algorithms/pad.rs and get rid of
internals.rs

* algorithms: protect all functions with pub(crate)

While it is expected that the functions inside algorithms crates might
be useful (and used) by other parties, they are low level functions and
as such impose a high risk of being misused. Protect all of them with
pub(crate) to prevent them from being exposed by mistake.

Also add big fat warnings to raw RSA functions, which should never be
used unless authors knows exactly what they are using.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2023-04-23 16:53:21 -06:00
Tony Arcieri
4df2262960
Use doc_auto_cfg (#303)
Automatically document feature-gated functionality
2023-04-19 09:46:14 -06:00
Tony Arcieri
3292db138d
v0.9.0-pre.2 (#302) 2023-04-19 09:06:51 -06:00
Dmitry Baryshkov
284fd79c1f
Remove primitive traits (#300)
The crate contains several exported traits targeting
hardware-accelerated implementations (PublicKey, PrivateKey,
EncryptionPrimitive, DecriptionPrimitive). However these traits
overcomplicate internal structure of the crate. It is not clear, which
level of API can be implemented by the hardware accelerators.
The crate is already quite complicated, implementing both
PaddingScheme-based API and Signer/Verifier/Encryptor/Decryptor API.

Remove the complication for now. The proper level of indirection can be
introduced once support for actual hardware accelerators is implemented.

Inline and drop the RsaPrivateKey::raw_decryption_primitive() function.
There is no need to zeroize argument, it is ciphertext, so it can be
assumed to be safe.

Change raw_int_decryption_primitive() and raw_int_decryption_primitive()
to output Result<BigUint> instead of Result<Vec<u8>>, because they also
take BigUint rather than Vec<u8> or &[u8].

In order to simplify adding support for RSA hardware accelerators, move
all formatting and padding functions to a separate modules, making it
theoretically possible to use that for implementing support for
low-level RSA hardware accelerators.

Also follows the pkcs1v15 change and use BigUint as a Signature's
internal implementation.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2023-04-19 08:51:06 -06:00
Tony Arcieri
2ec8708541
pkcs1v15: use BigUint as Signature's inner type (#298)
This one half of #220.

Doing anything with a signature involves converting it from bytes into a
`BigUint`, so this changes the inner type the latter which is more
useful.

It should also help address #272, since it will enable doing those sort
of checks more eagerly.
2023-04-18 12:17:07 -06:00
Dmitry Baryshkov
a6fd36d5c5
feat: switch to RsaPssParams::new() (#299)
Switch to using RsaPssParams::new() from pkcs1 crate. This fixes the
issue reported by zlint for x509-cert, where SHA* digest algorithms had
empty parameters instead of NULL parameters (as required by Mozilla
policy and permitted by RFC4055).

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2023-04-18 11:13:52 -06:00
Tony Arcieri
1eb59f48f7
Impl Signer for pss::SigningKey (#297)
Gated under the `getrandom` feature.

Calls `RandomizedSigner` with `OsRng`.
2023-04-17 19:00:23 -06:00
Tony Arcieri
d3a25cd2b2
Cargo.toml: alphabetize feature names (#296) 2023-04-17 14:57:00 -06:00
Tony Arcieri
891a4caba9
Rename Pkcs1v15Sign::new_raw to Pkcs1v15Sign::new_unprefixed (#293)
Following #290, which amended `pkcs1v15::SigningKey`, this commit makes
a corresponding change to `Pkcs1v15Sign` so the method name is
consistent with `SigningKey::new_unprefixed`
2023-04-17 06:40:24 -06:00
Dmitry Baryshkov
842c1f60f7
pss: add random key generation for BlindedSigningKey (#295)
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2023-04-17 06:39:57 -06:00
Dmitry Baryshkov
e7201ed244
Remove 'unsalted' PSS handling (#294)
Current new() and random() functions cause confusion. There is the
default from ASN.1 encoding of RSAPSS parameters (20). There is also
another default of (mod_size - 2 - hash_size). And there is a
recommendation to use salt_len of hash_size.

Drop old defaults and always use digest output size as the salt_len.
Clearly document new default.

* pss: specify salt_len when verifying the message

All RSA PSS standards (e.g. RFC 8017) clearly specify that RSA PSS
verification has an explicit salt length parameter (rather than
determining it from the message). Drop our 'automagic' code and pass
salt length when verifying the message. Old functions now default to
digest output size as a hash length.

* pss: remove possible non-constant time operation in PSS salt handling

The emsa_pss_get_salt() is possibly non-constant-time op. Change it to
be a contant-time operation.

---------

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2023-04-16 18:04:56 -06:00
Dmitry Baryshkov
67515a0e5f
lib: stop using deprecated SigningKey<D>::new_with_prefix (#292)
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2023-04-14 18:57:05 -06:00
Tony Arcieri
bf1defd014
pkcs1v15: make *_with_prefix methods the default (#290)
Renames the following:

- `SigningKey::new` => `SigningKey::new_unprefixed`
- `SigningKey::new_with_prefix` => `SigningKey::new`
- `VerifyingKey::new` => `VerifyingKey::new_unprefixed`
- `VerifyingKey::new_with_prefix` => `VerifyingKey::new`

The `*_with_prefix` methods are preserved with a deprecation warning,
which should help people migrate to the new versions.

Closes #238
2023-04-11 06:37:34 -06:00
Tony Arcieri
55462794bd
README.md: consistency fixups (#288)
- Add "RustCrypto:" to crate title
- Use badge from buildstats.info that displays downloads
2023-04-05 13:57:05 -06:00
Tony Arcieri
bdf7609e18
README.md: link to officially hosted audit report (#287) 2023-04-05 08:45:37 -06:00
Tony Arcieri
534eca6ae8
v0.9.0-pre.1 (#286) 2023-04-04 21:10:12 -06:00
Dmitry Baryshkov
cf90255057
AssociatedAlgorithmIdentifier implementation (#278)
Implement associated AlgorithmIdentifier traits for PKCS1v15 and PSS keys

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2023-04-04 20:12:08 -06:00
Dmitry Baryshkov
70d185bb1c
Fixes for 'cargo clippy' and 'rustfmt' issues (#283)
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2023-04-02 17:15:08 -06:00
dependabot[bot]
11fd84f3eb
build(deps): bump base64ct from 1.5.3 to 1.6.0 (#279)
Bumps [base64ct](https://github.com/RustCrypto/formats) from 1.5.3 to 1.6.0.
- [Release notes](https://github.com/RustCrypto/formats/releases)
- [Commits](https://github.com/RustCrypto/formats/compare/base64ct/v1.5.3...base64ct/v1.6.0)

---
updated-dependencies:
- dependency-name: base64ct
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-01 09:05:50 -06:00
dependabot[bot]
c9ecfb60f1
build(deps): bump zeroize from 1.5.7 to 1.6.0 (#282)
Bumps [zeroize](https://github.com/RustCrypto/utils) from 1.5.7 to 1.6.0.
- [Release notes](https://github.com/RustCrypto/utils/releases)
- [Commits](https://github.com/RustCrypto/utils/compare/zeroize-v1.5.7...zeroize-v1.6.0)

---
updated-dependencies:
- dependency-name: zeroize
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-01 09:05:23 -06:00
Dmitry Baryshkov
933bbdf2c3
pss: add function to get salt length from RSA PSS keys (#277)
To create proper RsaPssParams it is necessary to determine the salt
length specified for the signing key. Add a function to get it from
signing keys.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2023-03-26 18:56:40 -06:00
Rickard Hallerbäck
eb60db6cd6
Fix README example (#276) 2023-03-24 09:26:46 -06:00
Dirk Stolle
1ea5055cbd
Replace unmaintained actions-rs/toolchain action in CI workflows (#275)
Basically all of the `actions-rs/*` actions are unmaintained. See
<https://github.com/actions-rs/toolchain/issues/216> for more
information. Due to their age they generate several warnings in
CI runs.

To get rid of some of those warnings the occurrences of
`actions-rs/toolchain` are replaced by `dtolnay/rust-toolchain`.
2023-03-20 18:06:12 -06:00
Tony Arcieri
31f25dacee
v0.9.0-pre.0 (#271) 2023-03-06 13:51:13 -07:00
Tony Arcieri
54ddb2802f
Bump pkcs1 to v0.7, pkcs8 to v0.10; MSRV 1.65 (#270) 2023-03-06 13:31:16 -07:00
Tony Arcieri
99397db9ca
Use namespaced features for serde; MSRV 1.60 (#268)
Reverts-the-revert from #254, reinstating #251

This reverts commit 26f38ad66a09fc42ed6d73e3b1864f0251db4e2d.

Since we need to upgrade `pkcs1` and `pkcs8`, which are MSRV 1.65, now
is a good time to start making brekaing changes again.
2023-03-05 18:34:51 -07:00
Matt Keeter
39d3eb95f2
Fix incorrect doc link (#267) 2023-03-02 10:05:53 -07:00
Tony Arcieri
c2a16aac47
v0.8.2 (#266) 2023-03-01 21:54:18 -07:00
Diego
3061c9c5bf
fix: correct pss sign/verify when key length is multiple of 8 + 1 bits.
Co-authored-by: Diego Fabregat Traver <diego.fabregat@rwth-aachen.de>
2023-02-14 22:33:27 +01:00
Dmitry Baryshkov
dacabfc5ff
Add Encryption-related traits (#259)
* feat: relax Sized requirement for random source parameters

* oaep: move OAEP test cases to src/oaep.rs

There is little point in having only OAEP test cases in src/key.rs. Move
them to proper module, oaep.rs.

* oaep: mark two functions as private

Currently the crate doesn't mark the oaep module as public. Thus it
makes little sense to mark top-level functions as public. Drop the
modifier.

* feat: traits: add traits for encryption and decryption

Add traits following the signature design for encryption and decryption.

* oaep: add support for new encryption API

Add new EncryptingKey and DecryptingKey structs implementing Encryptor /
Decryptor traits.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2023-02-13 08:35:20 -07:00