302 Commits

Author SHA1 Message Date
Tony Arcieri
49b6c7e6ba
README.md: add notes about timing variability (#373)
Notes that the modpow implementation is not constant-time, but timing
variability is masked using random blinding.
2023-10-16 11:11:37 -06:00
Tony Arcieri
3a2906675a
Cargo.lock: update dependencies (#371)
Bumps the following dependencies:

    $ cargo update
    Updating crates.io index
    Updating errno v0.3.2 -> v0.3.4
    Updating fastrand v2.0.0 -> v2.0.1
    Updating libc v0.2.147 -> v0.2.148
    Updating linux-raw-sys v0.4.5 -> v0.4.8
    Updating proc-macro2 v1.0.66 -> v1.0.67
    Updating proptest v1.2.0 -> v1.3.1
    Updating regex-syntax v0.6.29 -> v0.7.5
    Updating rustix v0.38.8 -> v0.38.15
    Updating serde v1.0.185 -> v1.0.188
    Updating serde_derive v1.0.185 -> v1.0.188
    Updating sha1 v0.10.5 -> v0.10.6
    Updating sha2 v0.10.7 -> v0.10.8
    Updating smallvec v1.11.0 -> v1.11.1
    Updating syn v2.0.29 -> v2.0.37
    Updating typenum v1.16.0 -> v1.17.0
    Updating unicode-ident v1.0.11 -> v1.0.12
2023-10-03 07:35:48 -06:00
dependabot[bot]
d7ba15c9ff
build(deps): bump actions/checkout from 3 to 4 (#370)
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-02 06:44:44 -06:00
Artyom Pavlov
dfb12ac5bc
Set min version of serde to 1.0.184 (#360) 2023-08-21 11:47:22 +00:00
Artyom Pavlov
3e17a67d5e
Pin serde to <1.0.172 (#359) 2023-08-19 18:08:54 +03:00
Uli Schlachter
c04c65447e
Remove unused dependencies (#357)
Signed-off-by: Uli Schlachter <psychon@znc.in>
2023-08-18 06:53:24 -06:00
dependabot[bot]
e949b07f7f
build(deps): bump const-oid from 0.9.3 to 0.9.4 (#353)
Bumps [const-oid](https://github.com/RustCrypto/formats) from 0.9.3 to 0.9.4.
- [Commits](https://github.com/RustCrypto/formats/compare/const-oid/v0.9.3...const-oid/v0.9.4)

---
updated-dependencies:
- dependency-name: const-oid
  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-08-01 06:12:01 -06:00
Tom Hebb
eb7e507f56
Add hazmat feature as a replacement for expose-internals (#352)
External access to these functions was removed in #304 when the old
`internals` module and `expose-internals` feature were removed. There
are some valid use cases for them, though (see #351), so let's bring
back a subset of what was in `internals` using the same naming and
documentation conventions that the aes crate uses for its hazardous
functions.

Much of the added or changed documentation is derived from that in
the `aes` crate.

Fixes #351.
2023-07-23 10:43:48 -06:00
dependabot[bot]
40069a5408
build(deps): bump const-oid from 0.9.2 to 0.9.3 (#348)
Bumps [const-oid](https://github.com/RustCrypto/formats) from 0.9.2 to 0.9.3.
- [Commits](https://github.com/RustCrypto/formats/compare/const-oid/v0.9.2...const-oid/v0.9.3)

---
updated-dependencies:
- dependency-name: const-oid
  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-07-01 06:58:49 -06:00
Tony Arcieri
aed51e718d
Impl PKCS#8/SPKI decoding traits for pkcs1v15 keys (#346)
Adds PKCS#8 (and via blanket impl, PKCS#1) and SPKI decoding trait
support to `pkcs1v15::{SigningKey, VerifyingKey}`.

Also adds basic tests that decoding and encoding works.
2023-06-29 14:29:22 -06:00
Tony Arcieri
c7b0eae935
Add clarifying comment for totient check in key generation (#345)
See #343 where it wasn't entirely clear
2023-06-29 13:14:12 -06:00
dependabot[bot]
823bb23162
build(deps): bump proptest from 1.1.0 to 1.2.0 (#336)
Bumps [proptest](https://github.com/proptest-rs/proptest) from 1.1.0 to 1.2.0.
- [Release notes](https://github.com/proptest-rs/proptest/releases)
- [Changelog](https://github.com/proptest-rs/proptest/blob/master/CHANGELOG.md)
- [Commits](https://github.com/proptest-rs/proptest/compare/v1.1.0...v1.2.0)

---
updated-dependencies:
- dependency-name: proptest
  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-06-01 07:05:54 -06:00
tison
b65f352299
pkcs1v15: add regression test (#332)
Signed-off-by: tison <wander4096@gmail.com>
2023-05-12 15:18:26 -06:00
Tony Arcieri
dfa23bccb4
v0.9.2 (#331) 2023-05-08 07:15:09 -06:00
Tony Arcieri
09254b0ab5
pkcs1v15: have fmt impls call SignatureEncoding::to_bytes (#330)
The `fmt::{LowerHex, UpperHex}` impls, with the latter called
vicariously via `fmt::Display`, were showing the unpadded signature
rather than the padded one.

This changes these impls to call `SignatureEncoding::to_bytes` first
before displaying the signature.
2023-05-08 07:04:05 -06:00
Arthur Gautier
7a58281a05
Adds support for the SignatureBitStringEncoding trait (#328) 2023-05-04 17:12:43 -06:00
Tony Arcieri
d61b501182
v0.9.1 (#327) 2023-05-03 19:36:27 -06:00
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