Skip to content

Commit 406af93

Browse files
kbkdf: enable missing_docs lint (#132)
1 parent f7bc0fd commit 406af93

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

kbkdf/src/lib.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
)]
77
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
88
#![forbid(unsafe_code)]
9+
#![warn(missing_docs)]
910

1011
use core::{fmt, marker::PhantomData, ops::Mul};
1112
use digest::{
@@ -18,8 +19,10 @@ use digest::{
1819

1920
pub mod sealed;
2021

22+
/// KBKDF error type.
2123
#[derive(Debug, PartialEq)]
2224
pub enum Error {
25+
/// Indicates that the requested length of the derived key is too large for the value of R specified.
2326
InvalidRequestSize,
2427
}
2528

@@ -36,13 +39,28 @@ impl fmt::Display for Error {
3639

3740
impl core::error::Error for Error {}
3841

39-
/// Parameters used for KBKDF
42+
/// Parameters used for KBKDF.
43+
///
44+
/// For more details, read the official specification: [NIST SP 800-108r1](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-108r1.pdf).
4045
pub struct Params<'k, 'l, 'c> {
46+
/// Key-derivation key.
47+
///
48+
/// key that is used as an input to a key-derivation function (along with other input data) to derive keying material.
4149
pub kin: &'k [u8],
50+
/// A string that identifies the purpose for the derived keying material, which is encoded as a bit string.
51+
///
52+
/// The encoding method for the Label is defined in a larger context, for example, in the protocol that uses a KDF.
4253
pub label: &'l [u8],
54+
/// A bit string containing the information related to the derived keying material.
55+
///
56+
/// It may include the identities of the parties who are deriving and/or using the derived keying material and,
57+
/// optionally, a nonce known by the parties who derive the keys.
4358
pub context: &'c [u8],
59+
/// A flag indicating whether to update the Prf with the requested key length.
4460
pub use_l: bool,
61+
/// A flag indicating whether to separate the label from the context with a NULL byte.
4562
pub use_separator: bool,
63+
/// A flag indicating whether to update the Prf with the iteration counter.
4664
pub use_counter: bool,
4765
}
4866

@@ -61,7 +79,7 @@ impl<'k, 'l, 'c> Params<'k, 'l, 'c> {
6179
}
6280
}
6381

64-
/// Parameters builders for [`Params`]
82+
/// Parameters builders for [`Params`].
6583
pub struct ParamsBuilder<'k, 'l, 'c>(Params<'k, 'l, 'c>);
6684

6785
impl<'k, 'l, 'c> ParamsBuilder<'k, 'l, 'c> {
@@ -144,7 +162,7 @@ where
144162
<Prf::OutputSize as Mul<U8>>::Output: Unsigned,
145163
{
146164
/// Derives `key` from `kin` and other parameters.
147-
fn derive(&self, params: Params) -> Result<Array<u8, K::KeySize>, Error> {
165+
fn derive(&self, params: Params<'_, '_, '_>) -> Result<Array<u8, K::KeySize>, Error> {
148166
// n - An integer whose value is the number of iterations of the PRF needed to generate L
149167
// bits of keying material
150168
let n: u32 = <KbkdfCore<K::KeySize, Prf::OutputSize> as KbkdfUser>::L::U32
@@ -226,15 +244,19 @@ where
226244
Ok(output)
227245
}
228246

229-
/// Input the IV in the PRF
247+
/// Input the IV in the PRF.
230248
fn input_iv(&self, _ki: &mut Option<Array<u8, Prf::OutputSize>>) {}
231249

232250
/// Whether the KI should be reinjected every round.
251+
///
252+
/// Or, in other words, whether the KBKDF is in Feedback Mode.
233253
const FEEDBACK_KI: bool = false;
234254

255+
/// Whether the KBKDF is in Double-Pipeline Mode.
235256
const DOUBLE_PIPELINE: bool = false;
236257
}
237258

259+
/// KBKDF in Counter Mode.
238260
pub struct Counter<Prf, K, R = U32> {
239261
_marker: PhantomData<(Prf, K, R)>,
240262
}
@@ -259,6 +281,7 @@ where
259281
{
260282
}
261283

284+
/// KBKDF in Feedback Mode.
262285
pub struct Feedback<'a, Prf, K, R = U32>
263286
where
264287
Prf: Mac,
@@ -271,6 +294,7 @@ impl<'a, Prf, K, R> Feedback<'a, Prf, K, R>
271294
where
272295
Prf: Mac,
273296
{
297+
/// Creates a new [`Feedback`] instance with an optional IV.
274298
pub fn new(iv: Option<&'a Array<u8, Prf::OutputSize>>) -> Self {
275299
Self {
276300
iv,
@@ -298,6 +322,7 @@ where
298322
const FEEDBACK_KI: bool = true;
299323
}
300324

325+
/// KBKDF in Double-Pipeline Mode.
301326
pub struct DoublePipeline<Prf, K, R = U32>
302327
where
303328
Prf: Mac,

kbkdf/src/sealed.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! The module provides the sealed trait [R].
2+
13
use digest::{
24
array::typenum::Unsigned,
35
consts::{U8, U16, U24, U32},
@@ -14,7 +16,7 @@ mod private {
1416
impl Sealed for U32 {}
1517
}
1618

17-
/// Marker used to register valid values for R in the KBKDF
19+
/// Marker used to register valid values for R in the KBKDF.
1820
pub trait R: Unsigned + private::Sealed {}
1921

2022
impl R for U8 {}

0 commit comments

Comments
 (0)