Skip to content

Commit

Permalink
Configure rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Dec 10, 2021
1 parent f613b12 commit 4b9773c
Show file tree
Hide file tree
Showing 14 changed files with 283 additions and 251 deletions.
6 changes: 6 additions & 0 deletions .cargo/license.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Facebook, Inc. and its affiliates.
//
// This source code is licensed under both the MIT license found in the
// LICENSE-MIT file in the root directory of this source tree and the Apache
// License, Version 2.0 found in the LICENSE-APACHE file in the root directory
// of this source tree.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install stable toolchain
- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
toolchain: nightly
override: true
components: rustfmt

Expand Down
8 changes: 8 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
format_code_in_doc_comments = true
format_strings = true
group_imports = "StdExternalCrate"
imports_granularity = "Module"
license_template_path = ".cargo/license.rs"
newline_style = "Unix"
unstable_features = true
wrap_comments = true
20 changes: 9 additions & 11 deletions src/group/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
// License, Version 2.0 found in the LICENSE-APACHE file in the root directory
// of this source tree.

use crate::errors::InternalError;
use crate::util::i2osp;
use core::ops::Add;

use digest::{BlockInput, Digest};
use generic_array::{
sequence::Concat,
typenum::{Unsigned, U1, U2},
ArrayLength, GenericArray,
};
use generic_array::sequence::Concat;
use generic_array::typenum::{Unsigned, U1, U2};
use generic_array::{ArrayLength, GenericArray};

use crate::errors::InternalError;
use crate::util::i2osp;

// Computes ceil(x / y)
fn div_ceil(x: usize, y: usize) -> usize {
Expand Down Expand Up @@ -79,10 +79,8 @@ where

#[cfg(test)]
mod tests {
use generic_array::{
typenum::{U128, U32},
GenericArray,
};
use generic_array::typenum::{U128, U32};
use generic_array::GenericArray;

struct Params {
msg: &'static str,
Expand Down
19 changes: 11 additions & 8 deletions src/group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ cfg_ristretto! {
mod ristretto;
}

use crate::errors::InternalError;
use core::ops::{Add, Mul, Sub};

use digest::{BlockInput, Digest};
use generic_array::{typenum::U1, ArrayLength, GenericArray};
use generic_array::typenum::U1;
use generic_array::{ArrayLength, GenericArray};
use rand_core::{CryptoRng, RngCore};
use subtle::ConstantTimeEq;
use zeroize::Zeroize;

use crate::errors::InternalError;

/// A prime-order subgroup of a base field (EC, prime-order field ...). This
/// subgroup is noted additively — as in the draft RFC — in this trait.
pub trait Group:
Expand Down Expand Up @@ -80,8 +83,8 @@ pub trait Group:
scalar_bits: &GenericArray<u8, Self::ScalarLen>,
) -> Result<Self::Scalar, InternalError>;

/// Return a scalar from its fixed-length bytes representation. If the scalar
/// is zero, then return an error.
/// Return a scalar from its fixed-length bytes representation. If the
/// scalar is zero, then return an error.
fn from_scalar_slice<'a>(
scalar_bits: impl Into<&'a GenericArray<u8, Self::ScalarLen>>,
) -> Result<Self::Scalar, InternalError> {
Expand All @@ -103,14 +106,14 @@ pub trait Group:
type ElemLen: ArrayLength<u8> + 'static;

/// Return an element from its fixed-length bytes representation. This is
/// the unchecked version, which does not check for deserializing the identity
/// element
/// the unchecked version, which does not check for deserializing the
/// identity element
fn from_element_slice_unchecked(
element_bits: &GenericArray<u8, Self::ElemLen>,
) -> Result<Self, InternalError>;

/// Return an element from its fixed-length bytes representation. If the element
/// is the identity element, return an error.
/// Return an element from its fixed-length bytes representation. If the
/// element is the identity element, return an error.
fn from_element_slice<'a>(
element_bits: impl Into<&'a GenericArray<u8, Self::ElemLen>>,
) -> Result<Self, InternalError> {
Expand Down
21 changes: 13 additions & 8 deletions src/group/p256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
// License, Version 2.0 found in the LICENSE-APACHE file in the root directory
// of this source tree.

// Note: This group implementation of p256 is experimental for now,
// until hash-to-curve or crypto-bigint are fully supported.
// Note: This group implementation of p256 is experimental for now, until
// hash-to-curve or crypto-bigint are fully supported.

#![allow(
clippy::borrow_interior_mutable_const,
clippy::declare_interior_mutable_const
)]

use super::Group;
use crate::errors::InternalError;
use core::ops::{Add, Div, Mul, Neg};
use core::str::FromStr;

use digest::{BlockInput, Digest};
use generic_array::typenum::{Unsigned, U1, U2, U32, U33, U48};
use generic_array::{ArrayLength, GenericArray};
Expand All @@ -32,6 +31,9 @@ use p256_::{AffinePoint, EncodedPoint, ProjectivePoint};
use rand_core::{CryptoRng, RngCore};
use subtle::{Choice, ConditionallySelectable};

use super::Group;
use crate::errors::InternalError;

// https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-11#section-8.2
// `L: 48`
pub type L = U48;
Expand Down Expand Up @@ -109,7 +111,9 @@ impl Group for ProjectivePoint {
<D as Add<U1>>::Output: ArrayLength<u8>,
{
// https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf#[{%22num%22:211,%22gen%22:0},{%22name%22:%22XYZ%22},70,700,0]
// P-256 `n` is defined as `115792089210356248762697446949407573529996955224135760342 422259061068512044369`
// P-256 `n` is defined as
// `115792089210356248762697446949407573529996955224135760342
// 422259061068512044369`
const N: Lazy<BigInt> = Lazy::new(|| {
BigInt::from_str(
"115792089210356248762697446949407573529996955224135760342422259061068512044369",
Expand Down Expand Up @@ -182,8 +186,8 @@ impl Group for ProjectivePoint {
/// Corresponds to the hash_to_curve_simple_swu() function defined in
/// <https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-11#appendix-F.2>
///
/// `cmov`, `mod_floor` and `modpow` needs to be made constant-time, which
/// will be supported after crypto-bigint is no longer experimental. See
/// `cmov`, `mod_floor` and `modpow` needs to be made constant-time, which will
/// be supported after crypto-bigint is no longer experimental. See
/// <https://github.com/novifinancial/voprf/issues/13> for more context.

#[allow(clippy::many_single_char_names)]
Expand Down Expand Up @@ -435,9 +439,10 @@ fn hash_to_curve_simple_swu<N: ArrayLength<u8>>(

#[cfg(test)]
mod tests {
use super::*;
use generic_array::typenum::U96;

use super::*;

struct Params {
msg: &'static str,
px: &'static str,
Expand Down
4 changes: 2 additions & 2 deletions src/group/ristretto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use generic_array::{
};
use rand_core::{CryptoRng, RngCore};

// `cfg` here is only needed because of a bug in Rust's crate feature documentation.
// See: https://github.com/rust-lang/rust/issues/83428
// `cfg` here is only needed because of a bug in Rust's crate feature documentation. See:
// https://github.com/rust-lang/rust/issues/83428
cfg_ristretto! {
/// The implementation of such a subgroup for Ristretto
impl Group for RistrettoPoint {
Expand Down
4 changes: 2 additions & 2 deletions src/group/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
use crate::errors::InternalError;
use crate::group::Group;

// Test that the deserialization of a group element should throw an error
// if the identity element can be deserialized properly
// Test that the deserialization of a group element should throw an error if the
// identity element can be deserialized properly

#[test]
fn test_group_properties() -> Result<(), InternalError> {
Expand Down
Loading

0 comments on commit 4b9773c

Please sign in to comment.