Skip to content

Commit

Permalink
Adding null crypto library
Browse files Browse the repository at this point in the history
  • Loading branch information
taprinz committed Feb 3, 2024
1 parent ffd10bb commit 651920f
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 81 deletions.
36 changes: 36 additions & 0 deletions spdmlib/src/crypto/crypto_null/aead_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// SPDX-License-Identifier: Apache-2.0 or MIT

use crate::crypto::SpdmAead;
use crate::error::{SpdmResult};

use crate::protocol::{SpdmAeadAlgo, SpdmAeadIvStruct, SpdmAeadKeyStruct};

pub static DEFAULT: SpdmAead = SpdmAead {
encrypt_cb: encrypt,
decrypt_cb: decrypt,
};

fn encrypt(
aead_algo: SpdmAeadAlgo,
key: &SpdmAeadKeyStruct,
iv: &SpdmAeadIvStruct,
aad: &[u8],
plain_text: &[u8],
tag: &mut [u8],
cipher_text: &mut [u8],
) -> SpdmResult<(usize, usize)> {
unimplemented!()
}

fn decrypt(
aead_algo: SpdmAeadAlgo,
key: &SpdmAeadKeyStruct,
iv: &SpdmAeadIvStruct,
aad: &[u8],
cipher_text: &[u8],
tag: &[u8],
plain_text: &mut [u8],
) -> SpdmResult<usize> {
unimplemented!()
}
22 changes: 22 additions & 0 deletions spdmlib/src/crypto/crypto_null/asym_verify_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2021 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 or MIT

use crate::crypto::{SpdmAsymVerify};
use crate::error::{SpdmResult};
use crate::protocol::{SpdmBaseAsymAlgo, SpdmBaseHashAlgo, SpdmSignatureStruct};

pub static DEFAULT: SpdmAsymVerify = SpdmAsymVerify {
verify_cb: asym_verify,
};

fn asym_verify(
base_hash_algo: SpdmBaseHashAlgo,
base_asym_algo: SpdmBaseAsymAlgo,
public_cert_der: &[u8],
data: &[u8],
signature: &SpdmSignatureStruct,
) -> SpdmResult {
unimplemented!()
}

19 changes: 19 additions & 0 deletions spdmlib/src/crypto/crypto_null/cert_operation_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2021 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 or MIT

use crate::crypto::SpdmCertOperation;
use crate::error::{SpdmResult};

pub static DEFAULT: SpdmCertOperation = SpdmCertOperation {
get_cert_from_cert_chain_cb: get_cert_from_cert_chain,
verify_cert_chain_cb: verify_cert_chain,
};

fn get_cert_from_cert_chain(cert_chain: &[u8], index: isize) -> SpdmResult<(usize, usize)> {
unimplemented!()
}

fn verify_cert_chain(cert_chain: &[u8]) -> SpdmResult {
unimplemented!()
}
54 changes: 54 additions & 0 deletions spdmlib/src/crypto/crypto_null/dhe_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) 2021 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 or MIT

extern crate alloc;
use alloc::boxed::Box;

use crate::crypto::{SpdmDhe, SpdmDheKeyExchange};
use crate::protocol::{SpdmDheAlgo, SpdmDheExchangeStruct, SpdmDheFinalKeyStruct};
use bytes::{BufMut, BytesMut};

pub static DEFAULT: SpdmDhe = SpdmDhe {
generate_key_pair_cb: generate_key_pair,
};

fn generate_key_pair(
dhe_algo: SpdmDheAlgo,
) -> Option<(SpdmDheExchangeStruct, Box<dyn SpdmDheKeyExchange + Send>)> {
unimplemented!()
}

impl SpdmDheKeyExchange for SpdmDheKeyExchangeP256 {
fn compute_final_key(
self: Box<Self>,
peer_pub_key: &SpdmDheExchangeStruct,
) -> Option<SpdmDheFinalKeyStruct> {
unimplemented!()
}
}

struct SpdmDheKeyExchangeP256();

impl SpdmDheKeyExchangeP256 {
fn generate_key_pair() -> Option<(SpdmDheExchangeStruct, Box<dyn SpdmDheKeyExchange + Send>)> {
unimplemented!()
}
}

struct SpdmDheKeyExchangeP384();

impl SpdmDheKeyExchange for SpdmDheKeyExchangeP384 {
fn compute_final_key(
self: Box<Self>,
peer_pub_key: &SpdmDheExchangeStruct,
) -> Option<SpdmDheFinalKeyStruct> {
unimplemented!()
}
}

impl SpdmDheKeyExchangeP384 {
fn generate_key_pair() -> Option<(SpdmDheExchangeStruct, Box<dyn SpdmDheKeyExchange + Send>)> {
unimplemented!()
}
}
45 changes: 45 additions & 0 deletions spdmlib/src/crypto/crypto_null/hash_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2021 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 or MIT


use crate::crypto::SpdmHash;
use crate::protocol::{SpdmBaseHashAlgo, SpdmDigestStruct};

#[cfg(not(feature = "hashed-transcript-data"))]
pub static DEFAULT: SpdmHash = SpdmHash {
hash_all_cb: hash_all,
};
#[cfg(feature = "hashed-transcript-data")]
pub static DEFAULT: SpdmHash = SpdmHash {
hash_all_cb: hash_all,
hash_ctx_init_cb: hash_ext::hash_ctx_init,
hash_ctx_update_cb: hash_ext::hash_ctx_update,
hash_ctx_finalize_cb: hash_ext::hash_ctx_finalize,
hash_ctx_dup_cb: hash_ext::hash_ctx_dup,
};

fn hash_all(base_hash_algo: SpdmBaseHashAlgo, data: &[u8]) -> Option<SpdmDigestStruct> {
unimplemented!()
}

#[cfg(feature = "hashed-transcript-data")]
mod hash_ext {
use crate::error::{SpdmResult};

pub fn hash_ctx_update(handle: usize, data: &[u8]) -> SpdmResult {
unimplemented!()
}

pub fn hash_ctx_finalize(handle: usize) -> Option<SpdmDigestStruct> {
unimplemented!()
}

pub fn hash_ctx_dup(handle: usize) -> Option<usize> {
unimplemented!()
}

pub fn hash_ctx_init(base_hash_algo: SpdmBaseHashAlgo) -> Option<usize> {
unimplemented!()
}
}
31 changes: 31 additions & 0 deletions spdmlib/src/crypto/crypto_null/hkdf_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2021 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 or MIT

use crate::crypto::SpdmHkdf;
use crate::protocol::{
SpdmBaseHashAlgo, SpdmHkdfInputKeyingMaterial, SpdmHkdfOutputKeyingMaterial,
SpdmHkdfPseudoRandomKey
};

pub static DEFAULT: SpdmHkdf = SpdmHkdf {
hkdf_extract_cb: hkdf_extract,
hkdf_expand_cb: hkdf_expand,
};

fn hkdf_extract(
hash_algo: SpdmBaseHashAlgo,
salt: &[u8],
ikm: &SpdmHkdfInputKeyingMaterial,
) -> Option<SpdmHkdfPseudoRandomKey> {
unimplemented!()
}

fn hkdf_expand(
hash_algo: SpdmBaseHashAlgo,
prk: &SpdmHkdfPseudoRandomKey,
info: &[u8],
out_size: u16,
) -> Option<SpdmHkdfOutputKeyingMaterial> {
unimplemented!()
}
25 changes: 25 additions & 0 deletions spdmlib/src/crypto/crypto_null/hmac_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2021 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 or MIT

use crate::crypto::SpdmHmac;
use crate::error::{SpdmResult};
use crate::protocol::{SpdmBaseHashAlgo, SpdmDigestStruct};

pub static DEFAULT: SpdmHmac = SpdmHmac {
hmac_cb: hmac,
hmac_verify_cb: hmac_verify,
};

fn hmac(base_hash_algo: SpdmBaseHashAlgo, key: &[u8], data: &[u8]) -> Option<SpdmDigestStruct> {
unimplemented!()
}

fn hmac_verify(
base_hash_algo: SpdmBaseHashAlgo,
key: &[u8],
data: &[u8],
hmac: &SpdmDigestStruct,
) -> SpdmResult {
unimplemented!()
}
12 changes: 12 additions & 0 deletions spdmlib/src/crypto/crypto_null/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) 2021 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 or MIT

pub mod aead_impl;
pub mod asym_verify_impl;
pub mod cert_operation_impl;
pub mod dhe_impl;
pub mod hash_impl;
pub mod hkdf_impl;
pub mod hmac_impl;
pub mod rand_impl;
14 changes: 14 additions & 0 deletions spdmlib/src/crypto/crypto_null/rand_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) 2021 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 or MIT

use crate::crypto::SpdmCryptoRandom;
use crate::error::{SpdmResult};

pub static DEFAULT: SpdmCryptoRandom = SpdmCryptoRandom {
get_random_cb: get_random,
};

fn get_random(data: &mut [u8]) -> SpdmResult<usize> {
unimplemented!()
}
Loading

0 comments on commit 651920f

Please sign in to comment.