cas-typescript-sdk 1.0.32 → 1.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Cargo.toml CHANGED
@@ -11,7 +11,9 @@ crate-type = ["cdylib"]
11
11
  napi = "2.16.17"
12
12
  napi-derive = "2.16.13"
13
13
  csbindgen = "1.9.3"
14
- cas-lib = "0.2.50"
14
+ cas-lib = "0.2.56"
15
+ zeroize = "1.8.1"
16
+ zeroizing-alloc = "0.1.0"
15
17
 
16
18
  [build-dependencies]
17
- napi-build = "1"
19
+ napi-build = "1"
package/README.md CHANGED
@@ -6,9 +6,7 @@ Ever wanted all of your most useful cryptographic operations in one module and n
6
6
  CAS is here to provide a unified development experience as an abstract layer to the RustCrypto and Dalek-Cryptography suite of algorithms.
7
7
  The official NPM page can be found [here](https://www.npmjs.com/package/cas-typescript-sdk).
8
8
 
9
- **Note: All work is experimental and we understand some benchmarks might not be the most optimal.**
10
-
11
- **[You can find some usage examples here](https://github.com/Cryptographic-API-Services/cas-typescript-sdk/blob/main/docs/EXAMPLES.md)**
9
+ **Note: All work is experimental and we understand some benchmarks might not be the most optimal.**\
12
10
 
13
11
  ## Consuming Library Documentation
14
12
  This Node.js NPM module is dependent on our Rust layer [cas-lib](https://github.com/Cryptographic-API-Services/cas-lib). that contains methods to run industry-standard cryptographic operations sequentially, on threads, and the thread pool.
package/index.node CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cas-typescript-sdk",
3
- "version": "1.0.32",
3
+ "version": "1.0.34",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -5,7 +5,7 @@ use super::types::CASSHAED25519DalekDigitalSignatureResult;
5
5
 
6
6
  #[napi]
7
7
  pub fn sha_256_ed25519_digital_signature(data_to_sign: Vec<u8>) -> CASSHAED25519DalekDigitalSignatureResult {
8
- return <SHA256ED25519DigitalSignature as ED25519DigitalSignature>::digital_signature_ed25519(&data_to_sign).into();
8
+ return <SHA256ED25519DigitalSignature as ED25519DigitalSignature>::digital_signature_ed25519(data_to_sign).into();
9
9
  }
10
10
 
11
11
  #[napi]
@@ -13,37 +13,25 @@ pub fn sha_256_ed25519_digital_signature_verify(public_key: Vec<u8>, data_to_ver
13
13
  if public_key.len() != 32 || signature.len() != 64 {
14
14
  return false;
15
15
  }
16
- let mut pk = [0u8; 32];
17
- pk.copy_from_slice(&public_key[..32]);
18
- let mut sig = [0u8; 64];
19
- sig.copy_from_slice(&signature[..64]);
20
- SHA256ED25519DigitalSignature::digital_signature_ed25519_verify(pk, &data_to_verify, sig)
16
+ SHA256ED25519DigitalSignature::digital_signature_ed25519_verify(public_key, data_to_verify, signature)
21
17
  }
22
18
 
23
19
 
24
20
  #[test]
25
21
  fn sha_256_ed25519_test() {
26
22
  let key_size: u32 = 1024;
27
- let data_to_sign = b"GetTheseBytes";
28
- let signature_result: CASSHAED25519DalekDigitalSignatureResult = SHA256ED25519DigitalSignature::digital_signature_ed25519(&data_to_sign.clone()).into();
29
- let mut pk = [0u8; 32];
30
- pk.copy_from_slice(&signature_result.public_key[..32]);
31
- let mut sig = [0u8; 64];
32
- sig.copy_from_slice(&signature_result.signature[..64]);
33
- let is_verified: bool = SHA256ED25519DigitalSignature::digital_signature_ed25519_verify(pk, data_to_sign, sig);
23
+ let data_to_sign = b"GetTheseBytes".to_vec();
24
+ let signature_result: CASSHAED25519DalekDigitalSignatureResult = SHA256ED25519DigitalSignature::digital_signature_ed25519(data_to_sign.clone()).into();
25
+ let is_verified: bool = SHA256ED25519DigitalSignature::digital_signature_ed25519_verify(signature_result.public_key, data_to_sign, signature_result.signature);
34
26
  assert_eq!(is_verified, true);
35
27
  }
36
28
 
37
29
  #[test]
38
30
  fn sha_512_ed25519_test_fail() {
39
31
  let key_size: u32 = 1024;
40
- let data_to_sign = b"GetTheseBytes";
41
- let signature_result: CASSHAED25519DalekDigitalSignatureResult = SHA256ED25519DigitalSignature::digital_signature_ed25519(&data_to_sign.clone()).into();
42
- let not_original_data = b"NOtTHoseBytes";
43
- let mut pk = [0u8; 32];
44
- pk.copy_from_slice(&signature_result.public_key[..32]);
45
- let mut sig = [0u8; 64];
46
- sig.copy_from_slice(&signature_result.signature[..64]);
47
- let is_verified: bool = SHA256ED25519DigitalSignature::digital_signature_ed25519_verify(pk, not_original_data, sig);
32
+ let data_to_sign = b"GetTheseBytes".to_vec();
33
+ let signature_result: CASSHAED25519DalekDigitalSignatureResult = SHA256ED25519DigitalSignature::digital_signature_ed25519(data_to_sign.clone()).into();
34
+ let not_original_data = b"NOtTHoseBytes".to_vec();
35
+ let is_verified: bool = SHA256ED25519DigitalSignature::digital_signature_ed25519_verify(signature_result.public_key, not_original_data, signature_result.signature);
48
36
  assert_eq!(is_verified, false);
49
37
  }
@@ -7,25 +7,23 @@ use super::types::CASSHAED25519DalekDigitalSignatureResult;
7
7
 
8
8
  #[napi]
9
9
  pub fn sha_512_ed25519_digital_signature(data_to_sign: Vec<u8>) -> CASSHAED25519DalekDigitalSignatureResult {
10
- return <SHA512ED25519DigitalSignature as ED25519DigitalSignature>::digital_signature_ed25519(&data_to_sign).into();
10
+ return <SHA512ED25519DigitalSignature as ED25519DigitalSignature>::digital_signature_ed25519(data_to_sign).into();
11
11
  }
12
12
 
13
13
  #[napi]
14
14
  pub fn sha_512_ed25519_digital_signature_verify(public_key: Vec<u8>, data_to_verify: Vec<u8>, signature: Vec<u8>) -> bool {
15
- let public_key_array: [u8; 32] = public_key.try_into().expect("public_key must be 32 bytes");
16
- let signature_array: [u8; 64] = signature.try_into().expect("signature must be 64 bytes");
17
15
  return <SHA512ED25519DigitalSignature as ED25519DigitalSignature>::digital_signature_ed25519_verify(
18
- public_key_array,
19
- &data_to_verify,
20
- signature_array,
16
+ public_key,
17
+ data_to_verify,
18
+ signature,
21
19
  );
22
20
  }
23
21
 
24
22
  #[test]
25
23
  fn sha_512_ed25519_test() {
26
24
  let key_size: u32 = 1024;
27
- let data_to_sign = b"GetTheseBytes";
28
- let signature_result: SHAED25519DalekDigitalSignatureResult = <SHA512ED25519DigitalSignature as ED25519DigitalSignature>::digital_signature_ed25519(&data_to_sign.clone());
25
+ let data_to_sign = b"GetTheseBytes".to_vec();
26
+ let signature_result: SHAED25519DalekDigitalSignatureResult = <SHA512ED25519DigitalSignature as ED25519DigitalSignature>::digital_signature_ed25519(data_to_sign.clone());
29
27
  let is_verified: bool = SHA512ED25519DigitalSignature::digital_signature_ed25519_verify(signature_result.public_key, data_to_sign, signature_result.signature);
30
28
  assert_eq!(is_verified, true);
31
29
  }
@@ -33,15 +31,13 @@ fn sha_512_ed25519_test() {
33
31
  #[test]
34
32
  fn sha_512_ed25519_test_fail() {
35
33
  let key_size: u32 = 1024;
36
- let data_to_sign = b"GetTheseBytes";
37
- let signature_result: CASSHAED25519DalekDigitalSignatureResult = <SHA512ED25519DigitalSignature as ED25519DigitalSignature>::digital_signature_ed25519(&data_to_sign.clone()).into();
34
+ let data_to_sign = b"GetTheseBytes".to_vec();
35
+ let signature_result: CASSHAED25519DalekDigitalSignatureResult = <SHA512ED25519DigitalSignature as ED25519DigitalSignature>::digital_signature_ed25519(data_to_sign.clone()).into();
38
36
  let not_original_data = b"NOtTHoseBytes".to_vec();
39
- let public_key_array: [u8; 32] = signature_result.public_key.clone().try_into().expect("public_key must be 32 bytes");
40
- let signature_array: [u8; 64] = signature_result.signature.clone().try_into().expect("signature must be 64 bytes");
41
37
  let is_verified: bool = SHA512ED25519DigitalSignature::digital_signature_ed25519_verify(
42
- public_key_array,
43
- &not_original_data,
44
- signature_array,
38
+ signature_result.public_key,
39
+ not_original_data,
40
+ signature_result.signature,
45
41
  );
46
42
  assert_eq!(is_verified, false);
47
43
  }
package/src/lib.rs CHANGED
@@ -1,3 +1,7 @@
1
+ use zeroizing_alloc::ZeroAlloc;
2
+
3
+ #[global_allocator]
4
+ static ALLOC: ZeroAlloc<std::alloc::System> = ZeroAlloc(std::alloc::System);
1
5
  mod password_hashers {
2
6
  pub mod argon2;
3
7
  pub mod bcrypt;
@@ -26,9 +26,7 @@ pub fn test_ascon128_nonce_generate() {
26
26
 
27
27
  #[napi]
28
28
  pub fn ascon128_encrypt(key: Vec<u8>, nonce: Vec<u8>, plaintext: Vec<u8>) -> Vec<u8> {
29
- let key_arr: [u8; 16] = key.try_into().expect("Key must be 16 bytes");
30
- let nonce_arr: [u8; 16] = nonce.try_into().expect("Nonce must be 16 bytes");
31
- return <AsconAead as CASAsconAead>::encrypt(key_arr, nonce_arr, plaintext);
29
+ return <AsconAead as CASAsconAead>::encrypt(key, nonce, plaintext);
32
30
  }
33
31
 
34
32
  #[test]
@@ -46,9 +44,7 @@ pub fn test_ascon128_encrypt() {
46
44
 
47
45
  #[napi]
48
46
  pub fn ascon128_decrypt(key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
49
- let key_arr: [u8; 16] = key.try_into().expect("Key must be 16 bytes");
50
- let nonce_arr: [u8; 16] = nonce.try_into().expect("Nonce must be 16 bytes");
51
- return <AsconAead as CASAsconAead>::decrypt(key_arr, nonce_arr, ciphertext);
47
+ return <AsconAead as CASAsconAead>::decrypt(key, nonce, ciphertext);
52
48
  }
53
49
 
54
50
  #[test]
@@ -20,46 +20,36 @@ pub fn aes256_key() -> Vec<u8> {
20
20
 
21
21
  #[napi]
22
22
  pub fn aes128_encrypt(aes_key: Vec<u8>, nonce: Vec<u8>, plaintext: Vec<u8>) -> Vec<u8> {
23
- let key: [u8; 16] = aes_key.try_into().expect("Key must be 16 bytes");
24
- let nonce_arr: [u8; 12] = nonce.try_into().expect("Nonce must be 12 bytes");
25
- <CASAES128 as CASAES128Encryption>::encrypt_plaintext(key, nonce_arr, plaintext)
23
+ <CASAES128 as CASAES128Encryption>::encrypt_plaintext(aes_key, nonce, plaintext)
26
24
  }
27
25
 
28
26
  #[napi]
29
27
  pub fn aes128_decrypt(aes_key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
30
- let key: [u8; 16] = aes_key.try_into().expect("Key must be 16 bytes");
31
- let nonce_arr: [u8; 12] = nonce.try_into().expect("Nonce must be 12 bytes");
32
- <CASAES128 as CASAES128Encryption>::decrypt_ciphertext(key, nonce_arr, ciphertext)
28
+ <CASAES128 as CASAES128Encryption>::decrypt_ciphertext(aes_key, nonce, ciphertext)
33
29
  }
34
30
 
35
31
  #[napi]
36
32
  pub fn aes256_encrypt(aes_key: Vec<u8>, nonce: Vec<u8>, plaintext: Vec<u8>) -> Vec<u8> {
37
- let key: [u8; 32] = aes_key.try_into().expect("Key must be 32 bytes");
38
- let nonce_arr: [u8; 12] = nonce.try_into().expect("Nonce must be 12 bytes");
39
- <CASAES256 as CASAES256Encryption>::encrypt_plaintext(key, nonce_arr, plaintext)
33
+ <CASAES256 as CASAES256Encryption>::encrypt_plaintext(aes_key, nonce, plaintext)
40
34
  }
41
35
 
42
36
  #[napi]
43
37
  pub fn aes256_decrypt(aes_key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
44
- let key: [u8; 32] = aes_key.try_into().expect("Key must be 32 bytes");
45
- let nonce_arr: [u8; 12] = nonce.try_into().expect("Nonce must be 12 bytes");
46
- <CASAES256 as CASAES256Encryption>::decrypt_ciphertext(key, nonce_arr, ciphertext)
38
+ <CASAES256 as CASAES256Encryption>::decrypt_ciphertext(aes_key, nonce, ciphertext)
47
39
  }
48
40
 
49
41
  #[napi]
50
42
  pub fn aes_256_key_from_x25519_shared_secret(
51
43
  shared_secret: Vec<u8>,
52
44
  ) -> CASAesKeyFromX25519SharedSecret {
53
- let shared_secret_arr: [u8; 32] = shared_secret.try_into().expect("Shared secret must be 32 bytes");
54
- return <CASAES256 as CASAES256Encryption>::key_from_x25519_shared_secret(shared_secret_arr).into();
45
+ return <CASAES256 as CASAES256Encryption>::key_from_x25519_shared_secret(shared_secret).into();
55
46
  }
56
47
 
57
48
  #[napi]
58
49
  pub fn aes_128_key_from_x25519_shared_secret(
59
50
  shared_secret: Vec<u8>,
60
51
  ) -> CASAesKeyFromX25519SharedSecret {
61
- let shared_secret_arr: [u8; 32] = shared_secret.try_into().expect("Shared secret must be 32 bytes");
62
- return <CASAES128 as CASAES128Encryption>::key_from_x25519_shared_secret(shared_secret_arr).into();
52
+ return <CASAES128 as CASAES128Encryption>::key_from_x25519_shared_secret(shared_secret).into();
63
53
  }
64
54
 
65
55
  #[test]