Skip to content

Commit 33661ea

Browse files
committed
Add constant for shared secret buffer size
We can remove the magic number currently used for length of the `SharedSecret` array by defining a const `BUF_SIZE`.
1 parent 9292fe1 commit 33661ea

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/ecdh.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ use key::{SecretKey, PublicKey};
2323
use ffi::{self, CPtr};
2424
use secp256k1_sys::types::{c_int, c_uchar, c_void};
2525

26+
/// The buffer size (in bytes) used by `SharedSecret`.
27+
const BUF_SIZE: usize = 256;
28+
2629
/// Enables two parties to create a shared secret without revealing their own secrets.
2730
///
2831
/// # Examples
@@ -42,20 +45,20 @@ use secp256k1_sys::types::{c_int, c_uchar, c_void};
4245
// ```
4346
#[derive(Copy, Clone)]
4447
pub struct SharedSecret {
45-
data: [u8; 256],
48+
data: [u8; BUF_SIZE],
4649
len: usize,
4750
}
4851
impl_raw_debug!(SharedSecret);
4952

5053
// This implementes `From<N>` for all `[u8; N]` arrays from 128bits(16 byte) to 2048bits allowing known hash lengths.
5154
// Lower than 128 bits isn't resistant to collisions any more.
52-
impl_from_array_len!(SharedSecret, 256, (16 20 28 32 48 64 96 128 256));
55+
impl_from_array_len!(SharedSecret, BUF_SIZE, (16 20 28 32 48 64 96 128 256)); // BUF_SIZE == 256
5356

5457
impl SharedSecret {
5558
/// Create an empty SharedSecret
5659
pub(crate) fn empty() -> SharedSecret {
5760
SharedSecret {
58-
data: [0u8; 256],
61+
data: [0u8; BUF_SIZE],
5962
len: 0,
6063
}
6164
}

0 commit comments

Comments
 (0)