This commit is contained in:
Adam Ierymenko
2023-08-07 14:37:17 -04:00
parent 6c657519a2
commit 893a6b7b25
14 changed files with 396 additions and 127 deletions
+20 -4
View File
@@ -59,8 +59,18 @@ extern "C" {
fn CCCryptorRelease(cryptor_ref: *mut c_void) -> i32;
fn CCCryptorGCMSetIV(cryptor_ref: *mut c_void, iv: *const c_void, iv_len: usize) -> i32;
fn CCCryptorGCMAddAAD(cryptor_ref: *mut c_void, aad: *const c_void, len: usize) -> i32;
fn CCCryptorGCMEncrypt(cryptor_ref: *mut c_void, data_in: *const c_void, data_in_len: usize, data_out: *mut c_void) -> i32;
fn CCCryptorGCMDecrypt(cryptor_ref: *mut c_void, data_in: *const c_void, data_in_len: usize, data_out: *mut c_void) -> i32;
fn CCCryptorGCMEncrypt(
cryptor_ref: *mut c_void,
data_in: *const c_void,
data_in_len: usize,
data_out: *mut c_void,
) -> i32;
fn CCCryptorGCMDecrypt(
cryptor_ref: *mut c_void,
data_in: *const c_void,
data_in_len: usize,
data_out: *mut c_void,
) -> i32;
fn CCCryptorGCMFinal(cryptor_ref: *mut c_void, tag: *mut c_void, tag_len: *mut usize) -> i32;
fn CCCryptorGCMReset(cryptor_ref: *mut c_void) -> i32;
}
@@ -141,9 +151,15 @@ impl<const ENCRYPT: bool> AesGcm<ENCRYPT> {
pub fn crypt_in_place(&mut self, data: &mut [u8]) {
unsafe {
if ENCRYPT {
assert_eq!(CCCryptorGCMEncrypt(self.0, data.as_ptr().cast(), data.len(), data.as_mut_ptr().cast()), 0);
assert_eq!(
CCCryptorGCMEncrypt(self.0, data.as_ptr().cast(), data.len(), data.as_mut_ptr().cast()),
0
);
} else {
assert_eq!(CCCryptorGCMDecrypt(self.0, data.as_ptr().cast(), data.len(), data.as_mut_ptr().cast()), 0);
assert_eq!(
CCCryptorGCMDecrypt(self.0, data.as_ptr().cast(), data.len(), data.as_mut_ptr().cast()),
0
);
}
}
}
+5 -1
View File
@@ -456,7 +456,11 @@ impl AesGmacSiv {
ciphertext_to_plaintext.len(),
&mut data_out_written,
);
CCCryptorGCMAddAAD(self.gmac, ciphertext_to_plaintext.as_ptr().cast(), ciphertext_to_plaintext.len());
CCCryptorGCMAddAAD(
self.gmac,
ciphertext_to_plaintext.as_ptr().cast(),
ciphertext_to_plaintext.len(),
);
}
}
+6 -2
View File
@@ -144,7 +144,9 @@ impl AesGmacSiv {
self.tmp[12] &= 0x7f;
unsafe {
self.ctr.cipher_init::<true>(ptr::null_mut(), ptr::null_mut(), self.tmp.as_ptr()).unwrap();
self.ctr
.cipher_init::<true>(ptr::null_mut(), ptr::null_mut(), self.tmp.as_ptr())
.unwrap();
}
}
@@ -196,7 +198,9 @@ impl AesGmacSiv {
tag_tmp[8..12].fill(0);
unsafe {
self.gmac.cipher_init::<true>(ptr::null_mut(), ptr::null_mut(), tag_tmp.as_ptr()).unwrap();
self.gmac
.cipher_init::<true>(ptr::null_mut(), ptr::null_mut(), tag_tmp.as_ptr())
.unwrap();
}
}
+5 -2
View File
@@ -41,7 +41,9 @@ impl<const ENCRYPT: bool> AesGcm<ENCRYPT> {
/// `iv` must be exactly 12 bytes in length, because that is what Aes supports.
fn reset_init_gcm(&mut self, iv: &[u8]) {
unsafe {
self.0.cipher_init::<ENCRYPT>(ptr::null(), ptr::null(), iv.as_ptr()).unwrap();
self.0
.cipher_init::<ENCRYPT>(ptr::null(), ptr::null(), iv.as_ptr())
.unwrap();
}
}
@@ -145,7 +147,8 @@ impl<const ENCRYPT: bool> Aes<ENCRYPT> {
fn reset(&self, key: &[u8; aes::AES_256_KEY_SIZE]) {
let ctx = self.0.lock().unwrap();
unsafe {
ctx.cipher_init::<ENCRYPT>(ptr::null(), key.as_ptr(), ptr::null()).unwrap();
ctx.cipher_init::<ENCRYPT>(ptr::null(), key.as_ptr(), ptr::null())
.unwrap();
}
}
}
+6 -3
View File
@@ -163,10 +163,12 @@ mod test {
#[test]
fn aes_gmac_siv_encrypt_decrypt() {
let aes_key_0: [u8; 32] = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32,
];
let aes_key_1: [u8; 32] = [
2, 3, 4, 5, 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
2, 3, 4, 5, 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32,
];
let iv: [u8; 8] = [0, 1, 2, 3, 4, 5, 6, 7];
@@ -186,7 +188,8 @@ mod test {
let tag = *c.encrypt_second_pass_finish();
let sha = crate::hash::SHA384::hash(&buf).to_vec();
let sha = to_hex(sha.as_slice());
if sha != "4dc97c10abb6112a3907e5eb588ea5123719442b715da994d9756b003677719824326973960268823d924f66491a16e6" {
if sha != "4dc97c10abb6112a3907e5eb588ea5123719442b715da994d9756b003677719824326973960268823d924f66491a16e6"
{
panic!("encrypt result hash check failed! {}", sha);
}
//println!("Encrypt OK, tag: {}, hash: {}", to_hex(&tag), sha);
+45 -10
View File
@@ -15,12 +15,34 @@ extern "C" {
fn EVP_CIPHER_CTX_free(ctx: *mut ffi::EVP_CIPHER_CTX);
fn EVP_CIPHER_CTX_new() -> *mut ffi::EVP_CIPHER_CTX;
fn EVP_EncryptInit_ex(ctx: *mut ffi::EVP_CIPHER_CTX, cipher: *const ffi::EVP_CIPHER, engine: *mut c_void, key: *const u8, iv: *const u8)
-> c_int;
fn EVP_DecryptInit_ex(ctx: *mut ffi::EVP_CIPHER_CTX, cipher: *const ffi::EVP_CIPHER, engine: *mut c_void, key: *const u8, iv: *const u8)
-> c_int;
fn EVP_EncryptUpdate(ctx: *mut ffi::EVP_CIPHER_CTX, out: *mut u8, outl: *mut c_int, in_: *const u8, inl: c_int) -> c_int;
fn EVP_DecryptUpdate(ctx: *mut ffi::EVP_CIPHER_CTX, out: *mut u8, outl: *mut c_int, in_: *const u8, inl: c_int) -> c_int;
fn EVP_EncryptInit_ex(
ctx: *mut ffi::EVP_CIPHER_CTX,
cipher: *const ffi::EVP_CIPHER,
engine: *mut c_void,
key: *const u8,
iv: *const u8,
) -> c_int;
fn EVP_DecryptInit_ex(
ctx: *mut ffi::EVP_CIPHER_CTX,
cipher: *const ffi::EVP_CIPHER,
engine: *mut c_void,
key: *const u8,
iv: *const u8,
) -> c_int;
fn EVP_EncryptUpdate(
ctx: *mut ffi::EVP_CIPHER_CTX,
out: *mut u8,
outl: *mut c_int,
in_: *const u8,
inl: c_int,
) -> c_int;
fn EVP_DecryptUpdate(
ctx: *mut ffi::EVP_CIPHER_CTX,
out: *mut u8,
outl: *mut c_int,
in_: *const u8,
inl: c_int,
) -> c_int;
fn EVP_EncryptFinal_ex(ctx: *mut ffi::EVP_CIPHER_CTX, out: *mut u8, outl: *mut c_int) -> c_int;
fn EVP_DecryptFinal_ex(ctx: *mut ffi::EVP_CIPHER_CTX, out: *mut u8, outl: *mut c_int) -> c_int;
fn EVP_CIPHER_CTX_ctrl(ctx: *mut ffi::EVP_CIPHER_CTX, type_: c_int, arg: c_int, ptr: *mut c_void) -> c_int;
@@ -48,7 +70,12 @@ impl CipherCtx {
impl CipherCtx {
/// Initializes the context for encryption or decryption.
/// All pointer fields can be null, in which case the corresponding field in the context is not updated.
pub unsafe fn cipher_init<const ENCRYPT: bool>(&self, t: *const ffi::EVP_CIPHER, key: *const u8, iv: *const u8) -> Result<(), ErrorStack> {
pub unsafe fn cipher_init<const ENCRYPT: bool>(
&self,
t: *const ffi::EVP_CIPHER,
key: *const u8,
iv: *const u8,
) -> Result<(), ErrorStack> {
let evp_f = if ENCRYPT {
EVP_EncryptInit_ex
} else {
@@ -84,7 +111,13 @@ impl CipherCtx {
let mut outlen = 0;
cvt(evp_f(self.0.as_ptr(), output, &mut outlen, input.as_ptr(), input.len() as c_int))?;
cvt(evp_f(
self.0.as_ptr(),
output,
&mut outlen,
input.as_ptr(),
input.len() as c_int,
))?;
Ok(())
}
@@ -157,7 +190,8 @@ mod test {
let key = [1u8; 16];
let ctx = CipherCtx::new().unwrap();
unsafe {
ctx.cipher_init::<true>(ffi::EVP_aes_128_ecb(), key.as_ptr(), ptr::null()).unwrap();
ctx.cipher_init::<true>(ffi::EVP_aes_128_ecb(), key.as_ptr(), ptr::null())
.unwrap();
ffi::EVP_CIPHER_CTX_set_padding(ctx.as_ptr(), 0);
assert_eq!(ffi::EVP_CIPHER_CTX_get_block_size(ctx.as_ptr()) as usize, 16);
@@ -166,7 +200,8 @@ mod test {
let p = val.as_mut_ptr();
ctx.update::<true>(&val, p).unwrap();
ctx.cipher_init::<false>(ptr::null(), key.as_ptr(), ptr::null()).unwrap();
ctx.cipher_init::<false>(ptr::null(), key.as_ptr(), ptr::null())
.unwrap();
ctx.update::<false>(&val, p).unwrap();
assert_eq!(val, origin);
+10 -2
View File
@@ -148,7 +148,11 @@ impl Error {
let data = match self.data {
Some(Cow::Borrowed(data)) => Some((data.as_ptr() as *mut c_char, 0)),
Some(Cow::Owned(ref data)) => {
let ptr = ffi::CRYPTO_malloc((data.len() + 1) as _, concat!(file!(), "\0").as_ptr() as _, line!() as _) as *mut c_char;
let ptr = ffi::CRYPTO_malloc(
(data.len() + 1) as _,
concat!(file!(), "\0").as_ptr() as _,
line!() as _,
) as *mut c_char;
if ptr.is_null() {
None
} else {
@@ -169,7 +173,11 @@ impl Error {
fn put_error(&self) {
unsafe {
ffi::ERR_new();
ffi::ERR_set_debug(self.file.as_ptr(), self.line, self.func.as_ref().map_or(ptr::null(), |s| s.as_ptr()));
ffi::ERR_set_debug(
self.file.as_ptr(),
self.line,
self.func.as_ref().map_or(ptr::null(), |s| s.as_ptr()),
);
ffi::ERR_set_error(ffi::ERR_GET_LIB(self.code), ffi::ERR_GET_REASON(self.code), ptr::null());
}
}
+23 -5
View File
@@ -173,7 +173,13 @@ unsafe impl Send for SHA384 {}
extern "C" {
fn HMAC_CTX_new() -> *mut c_void;
fn HMAC_CTX_reset(ctx: *mut c_void) -> c_int;
fn HMAC_Init_ex(ctx: *mut c_void, key: *const c_void, key_len: c_int, evp_md: *const c_void, _impl: *const c_void) -> c_int;
fn HMAC_Init_ex(
ctx: *mut c_void,
key: *const c_void,
key_len: c_int,
evp_md: *const c_void,
_impl: *const c_void,
) -> c_int;
fn HMAC_Update(ctx: *mut c_void, data: *const c_void, len: usize) -> c_int;
fn HMAC_Final(ctx: *mut c_void, output: *mut c_void, output_len: *mut c_uint) -> c_int;
fn HMAC_CTX_free(ctx: *mut c_void);
@@ -192,7 +198,10 @@ impl HMACSHA512 {
unsafe {
let hm = Self { ctx: HMAC_CTX_new(), evp_md: EVP_sha512() };
assert!(!hm.ctx.is_null());
assert_ne!(HMAC_Init_ex(hm.ctx, key.as_ptr().cast(), key.len() as c_int, hm.evp_md, null()), 0);
assert_ne!(
HMAC_Init_ex(hm.ctx, key.as_ptr().cast(), key.len() as c_int, hm.evp_md, null()),
0
);
hm
}
}
@@ -201,7 +210,10 @@ impl HMACSHA512 {
pub fn reset(&mut self, key: &[u8]) {
unsafe {
assert_ne!(HMAC_CTX_reset(self.ctx), 0);
assert_ne!(HMAC_Init_ex(self.ctx, key.as_ptr().cast(), key.len() as c_int, self.evp_md, null()), 0);
assert_ne!(
HMAC_Init_ex(self.ctx, key.as_ptr().cast(), key.len() as c_int, self.evp_md, null()),
0
);
}
}
@@ -264,7 +276,10 @@ impl HMACSHA384 {
unsafe {
let hm = Self { ctx: HMAC_CTX_new(), evp_md: EVP_sha384() };
assert!(!hm.ctx.is_null());
assert_ne!(HMAC_Init_ex(hm.ctx, key.as_ptr().cast(), key.len() as c_int, hm.evp_md, null()), 0);
assert_ne!(
HMAC_Init_ex(hm.ctx, key.as_ptr().cast(), key.len() as c_int, hm.evp_md, null()),
0
);
hm
}
}
@@ -273,7 +288,10 @@ impl HMACSHA384 {
pub fn reset(&mut self, key: &[u8]) {
unsafe {
assert_ne!(HMAC_CTX_reset(self.ctx), 0);
assert_ne!(HMAC_Init_ex(self.ctx, key.as_ptr().cast(), key.len() as c_int, self.evp_md, null()), 0);
assert_ne!(
HMAC_Init_ex(self.ctx, key.as_ptr().cast(), key.len() as c_int, self.evp_md, null()),
0
);
}
}
+18 -3
View File
@@ -26,7 +26,13 @@ pub const P384_ECDSA_SIGNATURE_SIZE: usize = 96;
pub const P384_ECDH_SHARED_SECRET_SIZE: usize = 48;
extern "C" {
fn ECDH_compute_key(out: *mut u8, outlen: c_ulong, pub_key: *const ffi::EC_POINT, ecdh: *mut ffi::EC_KEY, kdf: *const c_void) -> c_int;
fn ECDH_compute_key(
out: *mut u8,
outlen: c_ulong,
pub_key: *const ffi::EC_POINT,
ecdh: *mut ffi::EC_KEY,
kdf: *const c_void,
) -> c_int;
}
/// A NIST P-384 ECDH/ECDSA public key.
pub struct P384PublicKey {
@@ -236,7 +242,10 @@ impl P384KeyPair {
let mut b = [0_u8; P384_ECDSA_SIGNATURE_SIZE];
// Read the signature's raw bytes out of OpenSSL.
ffi::BN_bn2bin(r, b[(CAP - r_len)..CAP].as_mut_ptr());
ffi::BN_bn2bin(s, b[(P384_ECDSA_SIGNATURE_SIZE - s_len)..P384_ECDSA_SIGNATURE_SIZE].as_mut_ptr());
ffi::BN_bn2bin(
s,
b[(P384_ECDSA_SIGNATURE_SIZE - s_len)..P384_ECDSA_SIGNATURE_SIZE].as_mut_ptr(),
);
ffi::ECDSA_SIG_free(sig);
b
}
@@ -328,7 +337,13 @@ impl OSSLKey {
let bnc = OSSLBNC::new()?;
let point = Point::new()?;
// Ask OpenSSL to read the raw bytes into the OpenSSL object.
cvt(ffi::EC_POINT_oct2point(GROUP_P384.0, point.0, buffer.as_ptr(), buffer.len(), bnc.0))?;
cvt(ffi::EC_POINT_oct2point(
GROUP_P384.0,
point.0,
buffer.as_ptr(),
buffer.len(),
bnc.0,
))?;
// Check if the object is valid.
if cvt_n(ffi::EC_POINT_is_on_curve(GROUP_P384.0, point.0, bnc.0))? == 1 {
// Create an OpenSSL key and guarantee to the caller that the key was initialized with a
File diff suppressed because it is too large Load Diff
+6 -6
View File
@@ -26,12 +26,12 @@ mod tests {
use crate::poly1305::*;
const TV0_INPUT: [u8; 32] = [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];
const TV0_KEY: [u8; 32] = [
0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x33, 0x32, 0x2d, 0x62, 0x79, 0x74, 0x65, 0x20, 0x6b, 0x65, 0x79, 0x20, 0x66, 0x6f, 0x72,
0x20, 0x50, 0x6f, 0x6c, 0x79, 0x31, 0x33, 0x30, 0x35,
0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x33, 0x32, 0x2d, 0x62, 0x79, 0x74, 0x65, 0x20, 0x6b, 0x65,
0x79, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x50, 0x6f, 0x6c, 0x79, 0x31, 0x33, 0x30, 0x35,
];
const TV0_TAG: [u8; 16] = [
0x49, 0xec, 0x78, 0x09, 0x0e, 0x48, 0x1e, 0xc6, 0xc2, 0x6b, 0x33, 0xb9, 0x1c, 0xcc, 0x03, 0x07,
@@ -39,8 +39,8 @@ mod tests {
const TV1_INPUT: [u8; 12] = [0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21];
const TV1_KEY: [u8; 32] = [
0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x33, 0x32, 0x2d, 0x62, 0x79, 0x74, 0x65, 0x20, 0x6b, 0x65, 0x79, 0x20, 0x66, 0x6f, 0x72,
0x20, 0x50, 0x6f, 0x6c, 0x79, 0x31, 0x33, 0x30, 0x35,
0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x33, 0x32, 0x2d, 0x62, 0x79, 0x74, 0x65, 0x20, 0x6b, 0x65,
0x79, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x50, 0x6f, 0x6c, 0x79, 0x31, 0x33, 0x30, 0x35,
];
const TV1_TAG: [u8; 16] = [
0xa6, 0xf7, 0x45, 0x00, 0x8f, 0x81, 0xc9, 0x16, 0xa2, 0x0d, 0xcc, 0x74, 0xee, 0xf2, 0xb2, 0xf0,
+18 -11
View File
@@ -166,12 +166,18 @@ impl<const ROUNDS: usize> Salsa<ROUNDS> {
*ciphertext.as_mut_ptr().cast::<u32>().add(7) = *plaintext.as_ptr().cast::<u32>().add(7) ^ x7;
*ciphertext.as_mut_ptr().cast::<u32>().add(8) = *plaintext.as_ptr().cast::<u32>().add(8) ^ x8;
*ciphertext.as_mut_ptr().cast::<u32>().add(9) = *plaintext.as_ptr().cast::<u32>().add(9) ^ x9;
*ciphertext.as_mut_ptr().cast::<u32>().add(10) = *plaintext.as_ptr().cast::<u32>().add(10) ^ x10;
*ciphertext.as_mut_ptr().cast::<u32>().add(11) = *plaintext.as_ptr().cast::<u32>().add(11) ^ x11;
*ciphertext.as_mut_ptr().cast::<u32>().add(12) = *plaintext.as_ptr().cast::<u32>().add(12) ^ x12;
*ciphertext.as_mut_ptr().cast::<u32>().add(13) = *plaintext.as_ptr().cast::<u32>().add(13) ^ x13;
*ciphertext.as_mut_ptr().cast::<u32>().add(14) = *plaintext.as_ptr().cast::<u32>().add(14) ^ x14;
*ciphertext.as_mut_ptr().cast::<u32>().add(15) = *plaintext.as_ptr().cast::<u32>().add(15) ^ x15;
*ciphertext.as_mut_ptr().cast::<u32>().add(10) =
*plaintext.as_ptr().cast::<u32>().add(10) ^ x10;
*ciphertext.as_mut_ptr().cast::<u32>().add(11) =
*plaintext.as_ptr().cast::<u32>().add(11) ^ x11;
*ciphertext.as_mut_ptr().cast::<u32>().add(12) =
*plaintext.as_ptr().cast::<u32>().add(12) ^ x12;
*ciphertext.as_mut_ptr().cast::<u32>().add(13) =
*plaintext.as_ptr().cast::<u32>().add(13) ^ x13;
*ciphertext.as_mut_ptr().cast::<u32>().add(14) =
*plaintext.as_ptr().cast::<u32>().add(14) ^ x14;
*ciphertext.as_mut_ptr().cast::<u32>().add(15) =
*plaintext.as_ptr().cast::<u32>().add(15) ^ x15;
}
}
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")))]
@@ -248,14 +254,15 @@ mod tests {
use crate::salsa::*;
const SALSA_20_TV0_KEY: [u8; 32] = [
0x0f, 0x62, 0xb5, 0x08, 0x5b, 0xae, 0x01, 0x54, 0xa7, 0xfa, 0x4d, 0xa0, 0xf3, 0x46, 0x99, 0xec, 0x3f, 0x92, 0xe5, 0x38, 0x8b, 0xde, 0x31,
0x84, 0xd7, 0x2a, 0x7d, 0xd0, 0x23, 0x76, 0xc9, 0x1c,
0x0f, 0x62, 0xb5, 0x08, 0x5b, 0xae, 0x01, 0x54, 0xa7, 0xfa, 0x4d, 0xa0, 0xf3, 0x46, 0x99, 0xec, 0x3f, 0x92,
0xe5, 0x38, 0x8b, 0xde, 0x31, 0x84, 0xd7, 0x2a, 0x7d, 0xd0, 0x23, 0x76, 0xc9, 0x1c,
];
const SALSA_20_TV0_IV: [u8; 8] = [0x28, 0x8f, 0xf6, 0x5d, 0xc4, 0x2b, 0x92, 0xf9];
const SALSA_20_TV0_KS: [u8; 64] = [
0x5e, 0x5e, 0x71, 0xf9, 0x01, 0x99, 0x34, 0x03, 0x04, 0xab, 0xb2, 0x2a, 0x37, 0xb6, 0x62, 0x5b, 0xf8, 0x83, 0xfb, 0x89, 0xce, 0x3b, 0x21,
0xf5, 0x4a, 0x10, 0xb8, 0x10, 0x66, 0xef, 0x87, 0xda, 0x30, 0xb7, 0x76, 0x99, 0xaa, 0x73, 0x79, 0xda, 0x59, 0x5c, 0x77, 0xdd, 0x59, 0x54,
0x2d, 0xa2, 0x08, 0xe5, 0x95, 0x4f, 0x89, 0xe4, 0x0e, 0xb7, 0xaa, 0x80, 0xa8, 0x4a, 0x61, 0x76, 0x66, 0x3f,
0x5e, 0x5e, 0x71, 0xf9, 0x01, 0x99, 0x34, 0x03, 0x04, 0xab, 0xb2, 0x2a, 0x37, 0xb6, 0x62, 0x5b, 0xf8, 0x83,
0xfb, 0x89, 0xce, 0x3b, 0x21, 0xf5, 0x4a, 0x10, 0xb8, 0x10, 0x66, 0xef, 0x87, 0xda, 0x30, 0xb7, 0x76, 0x99,
0xaa, 0x73, 0x79, 0xda, 0x59, 0x5c, 0x77, 0xdd, 0x59, 0x54, 0x2d, 0xa2, 0x08, 0xe5, 0x95, 0x4f, 0x89, 0xe4,
0x0e, 0xb7, 0xaa, 0x80, 0xa8, 0x4a, 0x61, 0x76, 0x66, 0x3f,
];
#[test]
+6 -2
View File
@@ -159,7 +159,10 @@ impl Ed25519KeyPair {
impl Clone for Ed25519KeyPair {
fn clone(&self) -> Self {
Self(ed25519_dalek::Keypair::from_bytes(&self.0.to_bytes()).unwrap(), self.1.clone())
Self(
ed25519_dalek::Keypair::from_bytes(&self.0.to_bytes()).unwrap(),
self.1.clone(),
)
}
}
@@ -169,7 +172,8 @@ pub fn ed25519_verify(public_key: &[u8], signature: &[u8], msg: &[u8]) -> bool {
let mut h = ed25519_dalek::Sha512::new();
let _ = h.write_all(msg);
let sig: [u8; 64] = signature[0..64].try_into().unwrap();
pk.verify_prehashed(h, None, &ed25519_dalek::Signature::from(sig)).is_ok()
pk.verify_prehashed(h, None, &ed25519_dalek::Signature::from(sig))
.is_ok()
})
} else {
false
+1 -1
View File
@@ -1,5 +1,5 @@
#unstable_features = true
max_width = 150
max_width = 120
#use_small_heuristics = "Max"
edition = "2021"
#empty_item_single_line = true