cas-typescript-sdk 1.0.23 → 1.0.24
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 +3 -17
- package/index.d.ts +22 -21
- package/index.node +0 -0
- package/lib/asymmetric/RSAWrapper.d.ts +3 -3
- package/lib/asymmetric/RSAWrapper.js +1 -1
- package/lib/asymmetric/index.d.ts +2 -2
- package/lib/asymmetric/index.js +1 -3
- package/lib/digital-signature/digital-siganture-sha-512.d.ts +5 -5
- package/lib/digital-signature/digital-siganture-sha-512.js +2 -2
- package/lib/digital-signature/digital-signature-base.d.ts +3 -3
- package/lib/digital-signature/digital-signaturte-sha-256.d.ts +3 -3
- package/lib/digital-signature/index.d.ts +2 -1
- package/lib/hybrid/types/aes-rsa-hybrid-initializer.d.ts +2 -2
- package/lib/index.d.ts +8 -9
- package/lib/index.js +22 -29
- package/lib/key_exchange/index.d.ts +2 -1
- package/lib/key_exchange/x25519.d.ts +2 -2
- package/lib/symmetric/aes-wrapper.d.ts +3 -3
- package/lib/symmetric/index.d.ts +2 -1
- package/package.json +1 -1
- package/src/asymmetric/cas_rsa.rs +13 -59
- package/src/digital_signature/sha_256_ed25519.rs +6 -42
- package/src/digital_signature/sha_256_rsa.rs +7 -63
- package/src/digital_signature/sha_512_ed25519.rs +8 -48
- package/src/digital_signature/sha_512_rsa.rs +9 -62
- package/src/digital_signature/types.rs +34 -0
- package/src/hashers/sha.rs +1 -35
- package/src/key_exchange/types.rs +17 -0
- package/src/key_exchange/x25519.rs +4 -36
- package/src/lib.rs +3 -8
- package/src/password_hashers/argon2.rs +4 -44
- package/src/password_hashers/bcrypt.rs +4 -31
- package/src/password_hashers/scrypt.rs +3 -42
- package/src/sponges/ascon_aead.rs +9 -39
- package/src/symmetric/aes.rs +12 -88
- package/src/symmetric/types.rs +17 -0
- package/src-ts/asymmetric/RSAWrapper.ts +3 -3
- package/src-ts/asymmetric/index.ts +2 -2
- package/src-ts/digital-signature/digital-siganture-sha-512.ts +5 -5
- package/src-ts/digital-signature/digital-signature-base.ts +3 -3
- package/src-ts/digital-signature/digital-signaturte-sha-256.ts +3 -3
- package/src-ts/digital-signature/index.ts +4 -1
- package/src-ts/hybrid/types/aes-rsa-hybrid-initializer.ts +2 -2
- package/src-ts/index.ts +8 -46
- package/src-ts/key_exchange/index.ts +2 -1
- package/src-ts/key_exchange/x25519.ts +2 -2
- package/src-ts/symmetric/aes-wrapper.ts +3 -3
- package/src-ts/symmetric/index.ts +2 -1
- package/test-ts/asymmetric.test.spec.ts +3 -3
- package/test-ts/digital-signature.test.spec.ts +5 -5
- package/test-ts/insecure-channel.test.spec.ts +5 -5
- package/src/asymmetric/cas_asymmetric_encryption.rs +0 -15
- package/src/digital_signature/cas_digital_signature_rsa.rs +0 -27
- package/src/hashers/blake2.rs +0 -37
- package/src/hashers/cas_hasher.rs +0 -8
- package/src/key_exchange/cas_key_exchange.rs +0 -6
- package/src/password_hashers/cas_password_hasher.rs +0 -4
- package/src/sponges/cas_ascon_aead.rs +0 -6
- package/src/symmetric/cas_symmetric_encryption.rs +0 -14
|
@@ -1,40 +1,10 @@
|
|
|
1
1
|
|
|
2
|
-
use
|
|
3
|
-
use ascon_aead::{aead::{generic_array::GenericArray, Aead, KeyInit, OsRng}, Ascon128};
|
|
2
|
+
use cas_lib::sponges::{ascon_aead::AsconAead, cas_ascon_aead::CASAsconAead};
|
|
4
3
|
use napi_derive::napi;
|
|
5
4
|
|
|
6
|
-
use super::cas_ascon_aead::{CASAsconAead};
|
|
7
|
-
pub struct AsconAead;
|
|
8
|
-
|
|
9
|
-
impl CASAsconAead for AsconAead {
|
|
10
|
-
fn encrypt(key: Vec<u8>, nonce: Vec<u8>, plaintext: Vec<u8>) -> Vec<u8> {
|
|
11
|
-
let key_generic_array = GenericArray::from_slice(&key);
|
|
12
|
-
let nonce_generic_array = GenericArray::from_slice(&nonce);
|
|
13
|
-
let cipher = Ascon128::new(key_generic_array);
|
|
14
|
-
let ciphertext = cipher.encrypt(&nonce_generic_array, plaintext.as_ref()).unwrap();
|
|
15
|
-
ciphertext
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
fn decrypt(key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
|
|
19
|
-
let key_generic_array = GenericArray::from_slice(&key);
|
|
20
|
-
let nonce_generic_array = GenericArray::from_slice(&nonce);
|
|
21
|
-
let cipher = Ascon128::new(key_generic_array);
|
|
22
|
-
let plaintext = cipher.decrypt(&nonce_generic_array, ciphertext.as_ref()).unwrap();
|
|
23
|
-
plaintext
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
fn generate_key() -> Vec<u8> {
|
|
27
|
-
return Ascon128::generate_key(&mut OsRng).to_vec();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
fn generate_nonce() -> Vec<u8> {
|
|
31
|
-
return Ascon128::generate_nonce(&mut OsRng).to_vec();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
5
|
#[napi]
|
|
36
6
|
pub fn ascon128_key_generate() -> Vec<u8> {
|
|
37
|
-
return AsconAead
|
|
7
|
+
return <AsconAead as CASAsconAead>::generate_key();
|
|
38
8
|
}
|
|
39
9
|
|
|
40
10
|
#[test]
|
|
@@ -45,7 +15,7 @@ fn test_ascon128_key_generate() {
|
|
|
45
15
|
|
|
46
16
|
#[napi]
|
|
47
17
|
pub fn ascon128_nonce_generate() -> Vec<u8> {
|
|
48
|
-
return AsconAead
|
|
18
|
+
return <AsconAead as CASAsconAead>::generate_nonce();
|
|
49
19
|
}
|
|
50
20
|
|
|
51
21
|
#[test]
|
|
@@ -56,13 +26,13 @@ pub fn test_ascon128_nonce_generate() {
|
|
|
56
26
|
|
|
57
27
|
#[napi]
|
|
58
28
|
pub fn ascon128_encrypt(key: Vec<u8>, nonce: Vec<u8>, plaintext: Vec<u8>) -> Vec<u8> {
|
|
59
|
-
return AsconAead
|
|
29
|
+
return <AsconAead as CASAsconAead>::encrypt(key, nonce, plaintext);
|
|
60
30
|
}
|
|
61
31
|
|
|
62
32
|
#[test]
|
|
63
33
|
pub fn test_ascon128_encrypt() {
|
|
64
|
-
let key = AsconAead
|
|
65
|
-
let nonce = AsconAead
|
|
34
|
+
let key = <AsconAead as CASAsconAead>::generate_key();
|
|
35
|
+
let nonce = <AsconAead as CASAsconAead>::generate_nonce();
|
|
66
36
|
let plaintext = b"Hello, World!".to_vec();
|
|
67
37
|
let ciphertext = ascon128_encrypt(key.clone(), nonce.clone(), plaintext.clone());
|
|
68
38
|
assert_ne!(ciphertext, plaintext);
|
|
@@ -70,13 +40,13 @@ pub fn test_ascon128_encrypt() {
|
|
|
70
40
|
|
|
71
41
|
#[napi]
|
|
72
42
|
pub fn ascon128_decrypt(key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
|
|
73
|
-
return AsconAead
|
|
43
|
+
return <AsconAead as CASAsconAead>::decrypt(key, nonce, ciphertext);
|
|
74
44
|
}
|
|
75
45
|
|
|
76
46
|
#[test]
|
|
77
47
|
pub fn test_ascon128_decrypt() {
|
|
78
|
-
let key = AsconAead
|
|
79
|
-
let nonce = AsconAead
|
|
48
|
+
let key = <AsconAead as CASAsconAead>::generate_key();
|
|
49
|
+
let nonce = <AsconAead as CASAsconAead>::generate_nonce();
|
|
80
50
|
let plaintext = b"Hello, World!".to_vec();
|
|
81
51
|
let ciphertext = ascon128_encrypt(key.clone(), nonce.clone(), plaintext.clone());
|
|
82
52
|
let decrypted = ascon128_decrypt(key.clone(), nonce.clone(), ciphertext.clone());
|
package/src/symmetric/aes.rs
CHANGED
|
@@ -1,85 +1,9 @@
|
|
|
1
|
-
use
|
|
1
|
+
use cas_lib::symmetric::{aes::{CASAES128, CASAES256}, cas_symmetric_encryption::CASAESEncryption};
|
|
2
2
|
use napi_derive::napi;
|
|
3
|
-
use rand::rngs::OsRng;
|
|
4
3
|
use rand::{RngCore, SeedableRng};
|
|
5
4
|
use rand_chacha::ChaCha20Rng;
|
|
6
5
|
|
|
7
|
-
use
|
|
8
|
-
aead::{generic_array::GenericArray, Aead},
|
|
9
|
-
Aes128Gcm, Aes256Gcm, KeyInit, Nonce,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
use super::cas_symmetric_encryption::{AesKeyFromX25519SharedSecret, CASAESEncryption};
|
|
13
|
-
pub struct CASAES128;
|
|
14
|
-
pub struct CASAES256;
|
|
15
|
-
|
|
16
|
-
impl CASAESEncryption for CASAES256 {
|
|
17
|
-
fn generate_key() -> Vec<u8> {
|
|
18
|
-
return Aes256Gcm::generate_key(&mut OsRng).to_vec();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
fn encrypt_plaintext(aes_key: Vec<u8>, nonce: Vec<u8>, plaintext: Vec<u8>) -> Vec<u8> {
|
|
22
|
-
let key = GenericArray::from_slice(&aes_key);
|
|
23
|
-
let mut cipher = Aes256Gcm::new(&key);
|
|
24
|
-
let nonce = Nonce::from_slice(&nonce);
|
|
25
|
-
let ciphertext = cipher.encrypt(nonce, plaintext.as_ref()).unwrap();
|
|
26
|
-
ciphertext
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
fn decrypt_ciphertext(aes_key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
|
|
30
|
-
let key = GenericArray::from_slice(&aes_key);
|
|
31
|
-
let mut cipher = Aes256Gcm::new(&key);
|
|
32
|
-
let nonce = Nonce::from_slice(&nonce);
|
|
33
|
-
let plaintext = cipher.decrypt(nonce, ciphertext.as_ref()).unwrap();
|
|
34
|
-
plaintext
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
fn key_from_x25519_shared_secret(shared_secret: Vec<u8>) -> AesKeyFromX25519SharedSecret {
|
|
38
|
-
let aes_key = Key::<Aes256Gcm>::from_slice(&shared_secret);
|
|
39
|
-
let mut aes_nonce: [u8; 12] = Default::default();
|
|
40
|
-
aes_nonce.copy_from_slice(&shared_secret[..12]);
|
|
41
|
-
let result = AesKeyFromX25519SharedSecret {
|
|
42
|
-
aes_key: aes_key.to_vec(),
|
|
43
|
-
aes_nonce: aes_nonce.to_vec(),
|
|
44
|
-
};
|
|
45
|
-
result
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
impl CASAESEncryption for CASAES128 {
|
|
50
|
-
fn generate_key() -> Vec<u8> {
|
|
51
|
-
return Aes128Gcm::generate_key(&mut OsRng).to_vec();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
fn encrypt_plaintext(aes_key: Vec<u8>, nonce: Vec<u8>, plaintext: Vec<u8>) -> Vec<u8> {
|
|
55
|
-
let key = GenericArray::from_slice(&aes_key);
|
|
56
|
-
let mut cipher = Aes128Gcm::new(&key);
|
|
57
|
-
let nonce = Nonce::from_slice(&nonce);
|
|
58
|
-
let ciphertext = cipher.encrypt(nonce, plaintext.as_ref()).unwrap();
|
|
59
|
-
ciphertext
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
fn decrypt_ciphertext(aes_key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
|
|
63
|
-
let key = GenericArray::from_slice(&aes_key);
|
|
64
|
-
let mut cipher = Aes128Gcm::new(&key);
|
|
65
|
-
let nonce = Nonce::from_slice(&nonce);
|
|
66
|
-
let plaintext = cipher.decrypt(nonce, ciphertext.as_ref()).unwrap();
|
|
67
|
-
plaintext
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
fn key_from_x25519_shared_secret(shared_secret: Vec<u8>) -> AesKeyFromX25519SharedSecret {
|
|
71
|
-
let mut aes_key: [u8; 16] = Default::default();
|
|
72
|
-
aes_key.copy_from_slice(&shared_secret[..16]);
|
|
73
|
-
let aes_key_slice = Key::<Aes128Gcm>::from_slice(&aes_key);
|
|
74
|
-
let mut aes_nonce: [u8; 12] = Default::default();
|
|
75
|
-
aes_nonce.copy_from_slice(&shared_secret[..12]);
|
|
76
|
-
let result = AesKeyFromX25519SharedSecret {
|
|
77
|
-
aes_key: aes_key_slice.to_vec(),
|
|
78
|
-
aes_nonce: aes_nonce.to_vec(),
|
|
79
|
-
};
|
|
80
|
-
result
|
|
81
|
-
}
|
|
82
|
-
}
|
|
6
|
+
use super::types::CASAesKeyFromX25519SharedSecret;
|
|
83
7
|
|
|
84
8
|
#[napi]
|
|
85
9
|
pub fn aes_nonce() -> Vec<u8> {
|
|
@@ -92,46 +16,46 @@ pub fn aes_nonce() -> Vec<u8> {
|
|
|
92
16
|
|
|
93
17
|
#[napi]
|
|
94
18
|
pub fn aes128_key() -> Vec<u8> {
|
|
95
|
-
return CASAES128
|
|
19
|
+
return <CASAES128 as CASAESEncryption>::generate_key();
|
|
96
20
|
}
|
|
97
21
|
|
|
98
22
|
#[napi]
|
|
99
23
|
pub fn aes256_key() -> Vec<u8> {
|
|
100
|
-
return CASAES256
|
|
24
|
+
return <CASAES256 as CASAESEncryption>::generate_key();
|
|
101
25
|
}
|
|
102
26
|
|
|
103
27
|
#[napi]
|
|
104
28
|
pub fn aes128_encrypt(aes_key: Vec<u8>, nonce: Vec<u8>, plaintext: Vec<u8>) -> Vec<u8> {
|
|
105
|
-
return CASAES128
|
|
29
|
+
return <CASAES128 as CASAESEncryption>::encrypt_plaintext(aes_key, nonce, plaintext);
|
|
106
30
|
}
|
|
107
31
|
|
|
108
32
|
#[napi]
|
|
109
33
|
pub fn aes128_decrypt(aes_key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
|
|
110
|
-
return CASAES128
|
|
34
|
+
return <CASAES128 as CASAESEncryption>::decrypt_ciphertext(aes_key, nonce, ciphertext);
|
|
111
35
|
}
|
|
112
36
|
|
|
113
37
|
#[napi]
|
|
114
38
|
pub fn aes256_encrypt(aes_key: Vec<u8>, nonce: Vec<u8>, plaintext: Vec<u8>) -> Vec<u8> {
|
|
115
|
-
return CASAES256
|
|
39
|
+
return <CASAES256 as CASAESEncryption>::encrypt_plaintext(aes_key, nonce, plaintext);
|
|
116
40
|
}
|
|
117
41
|
|
|
118
42
|
#[napi]
|
|
119
43
|
pub fn aes256_decrypt(aes_key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
|
|
120
|
-
return CASAES256
|
|
44
|
+
return <CASAES256 as CASAESEncryption>::decrypt_ciphertext(aes_key, nonce, ciphertext);
|
|
121
45
|
}
|
|
122
46
|
|
|
123
47
|
#[napi]
|
|
124
48
|
pub fn aes_256_key_from_x25519_shared_secret(
|
|
125
49
|
shared_secret: Vec<u8>,
|
|
126
|
-
) ->
|
|
127
|
-
return CASAES256
|
|
50
|
+
) -> CASAesKeyFromX25519SharedSecret {
|
|
51
|
+
return <CASAES256 as CASAESEncryption>::key_from_x25519_shared_secret(shared_secret).into();
|
|
128
52
|
}
|
|
129
53
|
|
|
130
54
|
#[napi]
|
|
131
55
|
pub fn aes_128_key_from_x25519_shared_secret(
|
|
132
56
|
shared_secret: Vec<u8>,
|
|
133
|
-
) ->
|
|
134
|
-
return CASAES128
|
|
57
|
+
) -> CASAesKeyFromX25519SharedSecret {
|
|
58
|
+
return <CASAES128 as CASAESEncryption>::key_from_x25519_shared_secret(shared_secret).into();
|
|
135
59
|
}
|
|
136
60
|
|
|
137
61
|
#[test]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
use cas_lib::symmetric::cas_symmetric_encryption::AesKeyFromX25519SharedSecret;
|
|
2
|
+
use napi_derive::napi;
|
|
3
|
+
|
|
4
|
+
#[napi(constructor)]
|
|
5
|
+
pub struct CASAesKeyFromX25519SharedSecret {
|
|
6
|
+
pub aes_key: Vec<u8>,
|
|
7
|
+
pub aes_nonce: Vec<u8>,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
impl From<AesKeyFromX25519SharedSecret> for CASAesKeyFromX25519SharedSecret {
|
|
11
|
+
fn from(value: AesKeyFromX25519SharedSecret) -> Self {
|
|
12
|
+
CASAesKeyFromX25519SharedSecret {
|
|
13
|
+
aes_key: value.aes_key,
|
|
14
|
+
aes_nonce: value.aes_nonce
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { decryptCiphertextRsa, encryptPlaintextRsa, generateRsaKeys,
|
|
1
|
+
import { CASRSAKeyPairResult, decryptCiphertextRsa, encryptPlaintextRsa, generateRsaKeys, signRsa, verifyRsa } from "../../index";
|
|
2
2
|
|
|
3
3
|
export class RSAWrapper {
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Generates an RSA key pair based of parameter sent in 1024, 2048, and 4096 are supported.
|
|
7
7
|
* @param keySize
|
|
8
|
-
* @returns
|
|
8
|
+
* @returns CASRSAKeyPairResult
|
|
9
9
|
*/
|
|
10
|
-
public generateKeys(keySize: number):
|
|
10
|
+
public generateKeys(keySize: number): CASRSAKeyPairResult {
|
|
11
11
|
if (keySize !== 1024 && keySize !== 2048 && keySize !== 4096) {
|
|
12
12
|
throw new Error("You must provide an appropriate key size to generate RSA keys");
|
|
13
13
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CASRSADigitalSignatureResult, CASSHAED25519DalekDigitalSignatureResult, sha512Ed25519DigitalSignature, sha512Ed25519DigitalSignatureVerify, sha512RsaDigitalSignature, sha512RsaVerifyDigitalSignature } from "../../index";
|
|
2
2
|
import { IDigitalSignature } from "./digital-signature-base";
|
|
3
3
|
|
|
4
4
|
export class DigitalSignatureSHA512Wrapper implements IDigitalSignature {
|
|
@@ -6,9 +6,9 @@ export class DigitalSignatureSHA512Wrapper implements IDigitalSignature {
|
|
|
6
6
|
/**
|
|
7
7
|
* Creates an ED25519 siganture from an array of bytes with SHA3-512.
|
|
8
8
|
* @param dataToSign
|
|
9
|
-
* @returns
|
|
9
|
+
* @returns CASSHAED25519DalekDigitalSignatureResult
|
|
10
10
|
*/
|
|
11
|
-
createED25519(dataToSign: number[]):
|
|
11
|
+
createED25519(dataToSign: number[]): CASSHAED25519DalekDigitalSignatureResult {
|
|
12
12
|
if (dataToSign?.length === 0) {
|
|
13
13
|
throw new Error("Must provide allocated data to sign");
|
|
14
14
|
}
|
|
@@ -39,9 +39,9 @@ export class DigitalSignatureSHA512Wrapper implements IDigitalSignature {
|
|
|
39
39
|
* Generates and RSA digital signature with SHA3-512
|
|
40
40
|
* @param rsa_key_size
|
|
41
41
|
* @param data_to_sign
|
|
42
|
-
* @returns
|
|
42
|
+
* @returns CASRSADigitalSignatureResult
|
|
43
43
|
*/
|
|
44
|
-
createRsa(rsa_key_size: number, data_to_sign: number[]):
|
|
44
|
+
createRsa(rsa_key_size: number, data_to_sign: number[]): CASRSADigitalSignatureResult {
|
|
45
45
|
if (rsa_key_size !== 1024 && rsa_key_size !== 2048 && rsa_key_size !== 4096) {
|
|
46
46
|
throw new Error("You need to provide an appropriate RSA key size.");
|
|
47
47
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CASRSADigitalSignatureResult, CASSHAED25519DalekDigitalSignatureResult } from "../../index";
|
|
2
2
|
|
|
3
3
|
export interface IDigitalSignature {
|
|
4
|
-
createRsa(rsa_key_size: number, data_to_sign: Array<number>):
|
|
4
|
+
createRsa(rsa_key_size: number, data_to_sign: Array<number>): CASRSADigitalSignatureResult;
|
|
5
5
|
verifyRSa(public_key: string, data_to_verify: Array<number>, signature: Array<number>): boolean;
|
|
6
|
-
createED25519(dataToSign: Array<number>):
|
|
6
|
+
createED25519(dataToSign: Array<number>): CASSHAED25519DalekDigitalSignatureResult;
|
|
7
7
|
verifyED25519(publicKey: Array<number>, dataToVerify: Array<number>, signature: Array<number>): boolean;
|
|
8
8
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CASRSADigitalSignatureResult, CASSHAED25519DalekDigitalSignatureResult, sha256Ed25519DigitalSignature, sha256Ed25519DigitalSignatureVerify, sha256RsaDigitalSignature, sha256RsaVerifyDigitalSignature, sha512Ed25519DigitalSignature } from "../../index";
|
|
2
2
|
import { IDigitalSignature } from "./digital-signature-base";
|
|
3
3
|
|
|
4
4
|
export class DigitalSignatureSHA256Wrapper implements IDigitalSignature {
|
|
@@ -8,7 +8,7 @@ export class DigitalSignatureSHA256Wrapper implements IDigitalSignature {
|
|
|
8
8
|
* @param dataToSign
|
|
9
9
|
* @returns SHAED25519DalekDigitalSignatureResult
|
|
10
10
|
*/
|
|
11
|
-
createED25519(dataToSign: number[]):
|
|
11
|
+
createED25519(dataToSign: number[]): CASSHAED25519DalekDigitalSignatureResult {
|
|
12
12
|
if (dataToSign?.length === 0) {
|
|
13
13
|
throw new Error("Must provide allocated data to sign");
|
|
14
14
|
}
|
|
@@ -41,7 +41,7 @@ export class DigitalSignatureSHA256Wrapper implements IDigitalSignature {
|
|
|
41
41
|
* @param data_to_sign
|
|
42
42
|
* @returns RsaDigitalSignatureResult
|
|
43
43
|
*/
|
|
44
|
-
createRsa(rsa_key_size: number, data_to_sign: number[]):
|
|
44
|
+
createRsa(rsa_key_size: number, data_to_sign: number[]): CASRSADigitalSignatureResult {
|
|
45
45
|
if (rsa_key_size !== 1024 && rsa_key_size !== 2048 && rsa_key_size !== 4096) {
|
|
46
46
|
throw new Error("You need to provide an appropriate RSA key size.");
|
|
47
47
|
}
|
|
@@ -2,10 +2,13 @@ import { DigitalSignatureType } from "./digital-signature-factory";
|
|
|
2
2
|
import { DigitalSignatureFactory } from "./digital-signature-factory";
|
|
3
3
|
import { DigitalSignatureSHA256Wrapper } from "./digital-signaturte-sha-256";
|
|
4
4
|
import { DigitalSignatureSHA512Wrapper } from "./digital-siganture-sha-512";
|
|
5
|
+
import { CASRSADigitalSignatureResult, CASSHAED25519DalekDigitalSignatureResult } from "../../index";
|
|
5
6
|
|
|
6
7
|
export {
|
|
7
8
|
DigitalSignatureFactory,
|
|
8
9
|
DigitalSignatureSHA256Wrapper,
|
|
9
10
|
DigitalSignatureSHA512Wrapper,
|
|
10
|
-
DigitalSignatureType
|
|
11
|
+
DigitalSignatureType,
|
|
12
|
+
CASSHAED25519DalekDigitalSignatureResult,
|
|
13
|
+
CASRSADigitalSignatureResult
|
|
11
14
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CASRSAKeyPairResult } from "../../..";
|
|
2
2
|
import { RSAWrapper } from "../../asymmetric";
|
|
3
3
|
import { AESWrapper } from "../../symmetric";
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@ export class AESRSAHybridInitializer {
|
|
|
6
6
|
public aesType: number;
|
|
7
7
|
public aesKey: Array<number>;
|
|
8
8
|
public aesNonce: Array<number>;
|
|
9
|
-
public rsaKeyPair:
|
|
9
|
+
public rsaKeyPair: CASRSAKeyPairResult;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Constructs an initalizer to use with Hybrid Encryption wrapper. Generates your RSA key pair, AES nonce, and AES key based on the parameters passed in.
|
package/src-ts/index.ts
CHANGED
|
@@ -1,46 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import { X25519Wrapper } from "./key_exchange/index";
|
|
10
|
-
import { AESWrapper } from "./symmetric/index";
|
|
11
|
-
import { RsaKeyPairResult, RSAWrapper } from "./asymmetric/index";
|
|
12
|
-
import {
|
|
13
|
-
AesRsaHybridEncryptResult,
|
|
14
|
-
AESRSAHybridInitializer,
|
|
15
|
-
HybridEncryptionWrapper,
|
|
16
|
-
} from "./hybrid/index";
|
|
17
|
-
import {
|
|
18
|
-
DigitalSignatureFactory,
|
|
19
|
-
DigitalSignatureSHA256Wrapper,
|
|
20
|
-
DigitalSignatureSHA512Wrapper,
|
|
21
|
-
DigitalSignatureType,
|
|
22
|
-
} from "./digital-signature";
|
|
23
|
-
import { AsconWrapper } from "./sponges/index";
|
|
24
|
-
|
|
25
|
-
export {
|
|
26
|
-
AesRsaHybridEncryptResult,
|
|
27
|
-
AESRSAHybridInitializer,
|
|
28
|
-
AESWrapper,
|
|
29
|
-
Argon2Wrapper,
|
|
30
|
-
AsconWrapper,
|
|
31
|
-
BCryptWrapper,
|
|
32
|
-
DigitalSignatureFactory,
|
|
33
|
-
DigitalSignatureSHA256Wrapper,
|
|
34
|
-
DigitalSignatureSHA512Wrapper,
|
|
35
|
-
DigitalSignatureType,
|
|
36
|
-
HasherFactory,
|
|
37
|
-
HasherType,
|
|
38
|
-
HybridEncryptionWrapper,
|
|
39
|
-
PasswordHasherFactory,
|
|
40
|
-
PasswordHasherType,
|
|
41
|
-
RsaKeyPairResult,
|
|
42
|
-
RSAWrapper,
|
|
43
|
-
ScryptWrapper,
|
|
44
|
-
SHAWrapper,
|
|
45
|
-
X25519Wrapper,
|
|
46
|
-
};
|
|
1
|
+
export * from "./password-hashers/index";
|
|
2
|
+
export * from "./hashers/index";
|
|
3
|
+
export * from "./key_exchange/index";
|
|
4
|
+
export * from "./symmetric/index";
|
|
5
|
+
export * from "./asymmetric/index";
|
|
6
|
+
export * from "./hybrid/index";
|
|
7
|
+
export * from "./digital-signature";
|
|
8
|
+
export * from "./sponges/index";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { x25519DiffieHellman, x25519GenerateSecretAndPublicKey
|
|
1
|
+
import { CASx25519SecretPublicKeyResult, x25519DiffieHellman, x25519GenerateSecretAndPublicKey } from "../../index"
|
|
2
2
|
|
|
3
3
|
export class X25519Wrapper {
|
|
4
4
|
/**
|
|
@@ -6,7 +6,7 @@ export class X25519Wrapper {
|
|
|
6
6
|
* User should share their public key with the other user and take the other user's public key and they can generate a Shared Secret.
|
|
7
7
|
* @returns X25519SecretPublicKeyResult
|
|
8
8
|
*/
|
|
9
|
-
public generateSecretAndPublicKey():
|
|
9
|
+
public generateSecretAndPublicKey(): CASx25519SecretPublicKeyResult {
|
|
10
10
|
return x25519GenerateSecretAndPublicKey();
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
CASAesKeyFromX25519SharedSecret,
|
|
3
3
|
aes128Decrypt,
|
|
4
4
|
aes128Encrypt,
|
|
5
5
|
aes128Key,
|
|
@@ -87,7 +87,7 @@ export class AESWrapper {
|
|
|
87
87
|
* @param shared_secret
|
|
88
88
|
* @returns
|
|
89
89
|
*/
|
|
90
|
-
public aes256KeyNonceX25519DiffieHellman(shared_secret: Array<number>):
|
|
90
|
+
public aes256KeyNonceX25519DiffieHellman(shared_secret: Array<number>): CASAesKeyFromX25519SharedSecret {
|
|
91
91
|
return aes256KeyFromX25519SharedSecret(shared_secret);
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -96,7 +96,7 @@ export class AESWrapper {
|
|
|
96
96
|
* @param shared_secret
|
|
97
97
|
* @returns
|
|
98
98
|
*/
|
|
99
|
-
public aes128KeyNonceX25519DiffieHellman(shared_secret: Array<number>):
|
|
99
|
+
public aes128KeyNonceX25519DiffieHellman(shared_secret: Array<number>): CASAesKeyFromX25519SharedSecret {
|
|
100
100
|
return aes128KeyFromX25519SharedSecret(shared_secret);
|
|
101
101
|
}
|
|
102
102
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { assert } from "chai";
|
|
2
|
-
import {
|
|
2
|
+
import { CASRSAKeyPairResult, RSAWrapper } from "..";
|
|
3
3
|
import { areEqual } from "./helpers/array";
|
|
4
4
|
|
|
5
5
|
describe("Asymmetric Tests", () => {
|
|
6
6
|
it("RSA 4096 encrypt and decrypt equals", () => {
|
|
7
7
|
const rsaWrapper: RSAWrapper = new RSAWrapper();
|
|
8
|
-
const keys:
|
|
8
|
+
const keys: CASRSAKeyPairResult = rsaWrapper.generateKeys(4096);
|
|
9
9
|
const tohashed: string = "This is my array to encrypt";
|
|
10
10
|
const encoder = new TextEncoder();
|
|
11
11
|
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
@@ -17,7 +17,7 @@ describe("Asymmetric Tests", () => {
|
|
|
17
17
|
|
|
18
18
|
it("RSA 2048 Sign and Verify", () => {
|
|
19
19
|
const rsaWrapper = new RSAWrapper();
|
|
20
|
-
const keys:
|
|
20
|
+
const keys: CASRSAKeyPairResult = rsaWrapper.generateKeys(2048);
|
|
21
21
|
const tohashed: string = "This is my encrypt";
|
|
22
22
|
const encoder = new TextEncoder();
|
|
23
23
|
const toSignBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assert } from "chai";
|
|
2
2
|
import { DigitalSignatureFactory, DigitalSignatureType } from "../src-ts/digital-signature/digital-signature-factory";
|
|
3
|
-
import {
|
|
3
|
+
import { CASRSADigitalSignatureResult } from "../index";
|
|
4
4
|
|
|
5
5
|
describe("Digital Signature", () => {
|
|
6
6
|
it("SHA 512 RSA pass", () => {
|
|
@@ -8,7 +8,7 @@ describe("Digital Signature", () => {
|
|
|
8
8
|
const tohashed: string = "This is my array to encrypt";
|
|
9
9
|
const encoder = new TextEncoder();
|
|
10
10
|
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
11
|
-
const dsResult:
|
|
11
|
+
const dsResult: CASRSADigitalSignatureResult = shaDsWrapper.createRsa(2048, tohashBytes);
|
|
12
12
|
const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, tohashBytes, dsResult.signature);
|
|
13
13
|
assert.equal(verify, true);
|
|
14
14
|
});
|
|
@@ -20,7 +20,7 @@ describe("Digital Signature", () => {
|
|
|
20
20
|
const encoder = new TextEncoder();
|
|
21
21
|
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
22
22
|
const badBytes: Array<number> = Array.from(encoder.encode(notOriginal));
|
|
23
|
-
const dsResult:
|
|
23
|
+
const dsResult: CASRSADigitalSignatureResult = shaDsWrapper.createRsa(4096, tohashBytes);
|
|
24
24
|
const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, badBytes, dsResult.signature);
|
|
25
25
|
assert.equal(verify, false);
|
|
26
26
|
});
|
|
@@ -30,7 +30,7 @@ describe("Digital Signature", () => {
|
|
|
30
30
|
const tohashed: string = "This is my array to encrypt";
|
|
31
31
|
const encoder = new TextEncoder();
|
|
32
32
|
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
33
|
-
const dsResult:
|
|
33
|
+
const dsResult: CASRSADigitalSignatureResult = shaDsWrapper.createRsa(2048, tohashBytes);
|
|
34
34
|
const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, tohashBytes, dsResult.signature);
|
|
35
35
|
assert.equal(verify, true);
|
|
36
36
|
});
|
|
@@ -42,7 +42,7 @@ describe("Digital Signature", () => {
|
|
|
42
42
|
const encoder = new TextEncoder();
|
|
43
43
|
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
44
44
|
const badBytes: Array<number> = Array.from(encoder.encode(notOriginal));
|
|
45
|
-
const dsResult:
|
|
45
|
+
const dsResult: CASRSADigitalSignatureResult = shaDsWrapper.createRsa(4096, tohashBytes);
|
|
46
46
|
const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, badBytes, dsResult.signature);
|
|
47
47
|
assert.equal(verify, false);
|
|
48
48
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {AESWrapper} from "../src-ts/symmetric/index";
|
|
2
2
|
import {X25519Wrapper} from "../src-ts/key_exchange/index";
|
|
3
|
-
import {
|
|
3
|
+
import {CASx25519SecretPublicKeyResult} from "../index";
|
|
4
4
|
import { areEqual } from "./helpers/array";
|
|
5
5
|
import { assert } from "chai";
|
|
6
6
|
|
|
@@ -8,8 +8,8 @@ describe("Insecure Channel Tests", () => {
|
|
|
8
8
|
it("AES256-GBC Diffie Hellman X25519", () => {
|
|
9
9
|
const aesWrapper = new AESWrapper();
|
|
10
10
|
const x25519Wrapper = new X25519Wrapper();
|
|
11
|
-
const alice_keys:
|
|
12
|
-
const bob_keys:
|
|
11
|
+
const alice_keys: CASx25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
|
|
12
|
+
const bob_keys: CASx25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
|
|
13
13
|
|
|
14
14
|
const alice_shared_secret = x25519Wrapper.generateSharedSecret(alice_keys.secretKey, bob_keys.publicKey);
|
|
15
15
|
const bob_shared_secret = x25519Wrapper.generateSharedSecret(bob_keys.secretKey, alice_keys.publicKey);
|
|
@@ -30,8 +30,8 @@ describe("Insecure Channel Tests", () => {
|
|
|
30
30
|
it("AES128-GBC Diffie Hellman X25519", () => {
|
|
31
31
|
const aesWrapper = new AESWrapper();
|
|
32
32
|
const x25519Wrapper = new X25519Wrapper();
|
|
33
|
-
const alice_keys:
|
|
34
|
-
const bob_keys:
|
|
33
|
+
const alice_keys: CASx25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
|
|
34
|
+
const bob_keys: CASx25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
|
|
35
35
|
|
|
36
36
|
const alice_shared_secret = x25519Wrapper.generateSharedSecret(alice_keys.secretKey, bob_keys.publicKey);
|
|
37
37
|
const bob_shared_secret = x25519Wrapper.generateSharedSecret(bob_keys.secretKey, alice_keys.publicKey);
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
use napi_derive::napi;
|
|
2
|
-
|
|
3
|
-
#[napi(constructor)]
|
|
4
|
-
pub struct RSAKeyPairResult {
|
|
5
|
-
pub private_key: String,
|
|
6
|
-
pub public_key: String,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
pub trait CASRSAEncryption {
|
|
10
|
-
fn generate_rsa_keys(key_size: u32) -> RSAKeyPairResult;
|
|
11
|
-
fn encrypt_plaintext(public_key: String, plaintext: Vec<u8>) -> Vec<u8>;
|
|
12
|
-
fn decrypt_ciphertext(private_key: String, ciphertext: Vec<u8>) -> Vec<u8>;
|
|
13
|
-
fn sign(private_key: String, hash: Vec<u8>) -> Vec<u8>;
|
|
14
|
-
fn verify(public_key: String, hash: Vec<u8>, signed_text: Vec<u8>) -> bool;
|
|
15
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
use napi_derive::napi;
|
|
2
|
-
|
|
3
|
-
#[napi(constructor)]
|
|
4
|
-
pub struct RSADigitalSignatureResult {
|
|
5
|
-
pub public_key: String,
|
|
6
|
-
pub private_key: String,
|
|
7
|
-
pub signature: Vec<u8>,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
#[napi(constructor)]
|
|
11
|
-
pub struct SHAED25519DalekDigitalSignatureResult {
|
|
12
|
-
pub public_key: Vec<u8>,
|
|
13
|
-
pub signature: Vec<u8>
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
pub trait RSADigitalSignature {
|
|
17
|
-
fn digital_signature_rsa(
|
|
18
|
-
rsa_key_size: u32,
|
|
19
|
-
data_to_sign: Vec<u8>,
|
|
20
|
-
) -> RSADigitalSignatureResult;
|
|
21
|
-
fn verify_rsa(public_key: String, data_to_verify: Vec<u8>, signature: Vec<u8>) -> bool;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
pub trait ED25519DigitalSignature {
|
|
25
|
-
fn digital_signature_ed25519(data_to_sign: Vec<u8>) -> SHAED25519DalekDigitalSignatureResult;
|
|
26
|
-
fn digital_signature_ed25519_verify(public_key: Vec<u8>, data_to_verify: Vec<u8>, signature: Vec<u8>) -> bool;
|
|
27
|
-
}
|