Skip to content

Commit 02c319c

Browse files
authored
Remove alloc crate feature from concat-kdf and ansi-x963-kdf (#106)
The crate feature is used only for the 3-line convenience functions, which can be easily written by users and probably extremely rarely used in practice.
1 parent 8169b38 commit 02c319c

File tree

4 files changed

+45
-117
lines changed

4 files changed

+45
-117
lines changed

ansi-x963-kdf/Cargo.toml

-8
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,3 @@ digest = "=0.11.0-pre.9"
1818
[dev-dependencies]
1919
hex-literal = "0.4"
2020
sha2 = { version = "=0.11.0-pre.4", default-features = false }
21-
22-
[features]
23-
alloc = []
24-
25-
[package.metadata.docs.rs]
26-
all-features = true
27-
rustdoc-args = ["--cfg", "docsrs"]
28-

ansi-x963-kdf/src/lib.rs

+24-53
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,9 @@
11
#![no_std]
22
#![doc = include_str!("../README.md")]
3-
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
43

54
use core::fmt;
65
use digest::{array::typenum::Unsigned, Digest, FixedOutputReset};
76

8-
#[cfg(feature = "alloc")]
9-
extern crate alloc;
10-
11-
/// ANSI-X9.63 KDF errors.
12-
#[derive(Clone, Copy, Debug, PartialEq)]
13-
pub enum Error {
14-
/// The length of the secret is zero.
15-
NoSecret,
16-
/// The length of the output is zero.
17-
NoOutput,
18-
/// The length of the input is too big
19-
InputOverflow,
20-
/// The length of the output is too big.
21-
CounterOverflow,
22-
}
23-
24-
impl fmt::Display for Error {
25-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
26-
f.write_str(match self {
27-
Error::NoSecret => "Buffer for secret has zero length.",
28-
Error::NoOutput => "Buffer for key has zero length.",
29-
Error::InputOverflow => "Input length is to big.",
30-
Error::CounterOverflow => "Requested key length is to big.",
31-
})
32-
}
33-
}
34-
35-
impl ::core::error::Error for Error {}
36-
377
/// Derives `key` in-place from `secret` and `shared_info`.
388
///
399
/// # Example
@@ -90,27 +60,28 @@ where
9060
Ok(())
9161
}
9262

93-
/// Derives and returns `length` bytes key from `secret` and `shared_info`.
94-
///
95-
/// # Example
96-
/// ```
97-
/// use hex_literal::hex;
98-
/// use sha2::Sha256;
99-
///
100-
/// let key = ansi_x963_kdf::derive_key::<Sha256>(b"secret", b"shared-info", 16).unwrap();
101-
/// assert_eq!(key[..], hex!("8dbb1d50bcc7fc782abc9db5c64a2826")[..]);
102-
/// ```
103-
#[cfg(feature = "alloc")]
104-
#[inline]
105-
pub fn derive_key<D>(
106-
secret: &[u8],
107-
shared_info: &[u8],
108-
length: usize,
109-
) -> Result<alloc::boxed::Box<[u8]>, Error>
110-
where
111-
D: Digest + FixedOutputReset,
112-
{
113-
let mut key = alloc::vec![0u8; length].into_boxed_slice();
114-
derive_key_into::<D>(secret, shared_info, &mut key)?;
115-
Ok(key)
63+
/// ANSI-X9.63 KDF errors.
64+
#[derive(Clone, Copy, Debug, PartialEq)]
65+
pub enum Error {
66+
/// The length of the secret is zero.
67+
NoSecret,
68+
/// The length of the output is zero.
69+
NoOutput,
70+
/// The length of the input is too big
71+
InputOverflow,
72+
/// The length of the output is too big.
73+
CounterOverflow,
11674
}
75+
76+
impl fmt::Display for Error {
77+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
78+
f.write_str(match self {
79+
Error::NoSecret => "Buffer for secret has zero length.",
80+
Error::NoOutput => "Buffer for key has zero length.",
81+
Error::InputOverflow => "Input length is to big.",
82+
Error::CounterOverflow => "Requested key length is to big.",
83+
})
84+
}
85+
}
86+
87+
impl core::error::Error for Error {}

concat-kdf/Cargo.toml

-7
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,3 @@ digest = "=0.11.0-pre.9"
1818
[dev-dependencies]
1919
hex-literal = "0.4"
2020
sha2 = { version = "=0.11.0-pre.4", default-features = false }
21-
22-
[features]
23-
alloc = []
24-
25-
[package.metadata.docs.rs]
26-
all-features = true
27-
rustdoc-args = ["--cfg", "docsrs"]

concat-kdf/src/lib.rs

+21-49
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,9 @@
11
#![no_std]
22
#![doc = include_str!("../README.md")]
3-
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
43

54
use core::fmt;
65
use digest::{array::typenum::Unsigned, Digest, FixedOutputReset, Update};
76

8-
#[cfg(feature = "alloc")]
9-
extern crate alloc;
10-
11-
/// Concat KDF errors.
12-
#[derive(Clone, Copy, Debug, PartialEq)]
13-
pub enum Error {
14-
/// The length of the secret is zero.
15-
NoSecret,
16-
/// The length of the output is zero.
17-
NoOutput,
18-
/// The length of the output is too big.
19-
CounterOverflow,
20-
}
21-
22-
impl fmt::Display for Error {
23-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
24-
f.write_str(match self {
25-
Error::NoSecret => "Buffer for secret has zero length.",
26-
Error::NoOutput => "Buffer for key has zero length.",
27-
Error::CounterOverflow => "Requested key length is to big.",
28-
})
29-
}
30-
}
31-
32-
impl ::core::error::Error for Error {}
33-
347
/// Derives `key` in-place from `secret` and `other_info`.
358
///
369
/// # Example
@@ -73,26 +46,25 @@ where
7346
Ok(())
7447
}
7548

76-
/// Derives and returns `length` bytes key from `secret` and `other_info`.
77-
///
78-
/// # Example
79-
/// ```rust
80-
/// use hex_literal::hex;
81-
/// use sha2::Sha256;
82-
///
83-
/// let key = concat_kdf::derive_key::<Sha256>(b"secret", b"shared-info", 16).unwrap();
84-
/// assert_eq!(key[..], hex!("960db2c549ab16d71a7b008e005c2bdc")[..]);
85-
/// ```
86-
#[cfg(feature = "alloc")]
87-
pub fn derive_key<D>(
88-
secret: &[u8],
89-
other_info: &[u8],
90-
length: usize,
91-
) -> Result<alloc::boxed::Box<[u8]>, Error>
92-
where
93-
D: Digest + FixedOutputReset,
94-
{
95-
let mut key = alloc::vec![0u8; length].into_boxed_slice();
96-
derive_key_into::<D>(secret, other_info, &mut key)?;
97-
Ok(key)
49+
/// Concat KDF errors.
50+
#[derive(Clone, Copy, Debug, PartialEq)]
51+
pub enum Error {
52+
/// The length of the secret is zero.
53+
NoSecret,
54+
/// The length of the output is zero.
55+
NoOutput,
56+
/// The length of the output is too big.
57+
CounterOverflow,
9858
}
59+
60+
impl fmt::Display for Error {
61+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
62+
f.write_str(match self {
63+
Error::NoSecret => "Buffer for secret has zero length.",
64+
Error::NoOutput => "Buffer for key has zero length.",
65+
Error::CounterOverflow => "Requested key length is to big.",
66+
})
67+
}
68+
}
69+
70+
impl core::error::Error for Error {}

0 commit comments

Comments
 (0)