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 +4 -2
- package/README.md +1 -3
- package/index.node +0 -0
- package/package.json +1 -1
- package/src/digital_signature/sha_256_ed25519.rs +9 -21
- package/src/digital_signature/sha_512_ed25519.rs +11 -15
- package/src/lib.rs +4 -0
- package/src/sponges/ascon_aead.rs +2 -6
- package/src/symmetric/aes.rs +6 -16
package/Cargo.toml
CHANGED
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
|
@@ -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(
|
|
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
|
-
|
|
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(
|
|
29
|
-
let
|
|
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(
|
|
42
|
-
let not_original_data = b"NOtTHoseBytes";
|
|
43
|
-
let
|
|
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(
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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(
|
|
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(
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
@@ -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
|
-
|
|
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
|
-
|
|
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]
|
package/src/symmetric/aes.rs
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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]
|