cas-typescript-sdk 1.0.30 → 1.0.32
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 +1 -1
- package/README.md +1 -2
- package/index.d.ts +8 -0
- package/index.node +0 -0
- package/lib/hashers/blake2-wrapper.d.ts +55 -0
- package/lib/hashers/blake2-wrapper.js +75 -0
- package/lib/hashers/hasher-factory.js +4 -0
- package/lib/hashers/hasher-type.d.ts +2 -1
- package/lib/hashers/hasher-type.js +1 -0
- package/lib/hashers/index.d.ts +2 -1
- package/lib/hashers/index.js +3 -1
- package/package.json +11 -11
- package/src/asymmetric/cas_rsa.rs +1 -1
- package/src/digital_signature/sha_256_ed25519.rs +25 -9
- package/src/digital_signature/sha_512_ed25519.rs +19 -7
- package/src/digital_signature/types.rs +2 -2
- package/src/hashers/blake2.rs +127 -0
- package/src/hashers/sha.rs +3 -3
- package/src/key_exchange/types.rs +3 -3
- package/src/key_exchange/x25519.rs +1 -1
- package/src/lib.rs +1 -0
- package/src/password_hashers/argon2.rs +4 -5
- package/src/password_hashers/bcrypt.rs +1 -1
- package/src/password_hashers/scrypt.rs +1 -1
- package/src/sponges/ascon_aead.rs +27 -11
- package/src/symmetric/aes.rs +20 -10
- package/src/symmetric/types.rs +15 -5
- package/src-ts/hashers/blake2-wrapper.ts +83 -0
- package/src-ts/hashers/hasher-factory.ts +3 -1
- package/src-ts/hashers/hasher-type.ts +2 -1
- package/src-ts/hashers/index.ts +2 -1
- package/test-ts/hasher.test.spec.ts +139 -7
- package/test-ts/symmetric.test.spec.ts +47 -0
package/Cargo.toml
CHANGED
package/README.md
CHANGED
|
@@ -8,8 +8,7 @@ The official NPM page can be found [here](https://www.npmjs.com/package/cas-type
|
|
|
8
8
|
|
|
9
9
|
**Note: All work is experimental and we understand some benchmarks might not be the most optimal.**
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
**[You can find some usage examples here](https://github.com/Cryptographic-API-Services/cas-typescript-sdk/blob/main/docs/EXAMPLES.md)**
|
|
13
12
|
|
|
14
13
|
## Consuming Library Documentation
|
|
15
14
|
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.d.ts
CHANGED
|
@@ -19,6 +19,14 @@ export declare function sha512(dataToHash: Array<number>): Array<number>
|
|
|
19
19
|
export declare function sha512Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
20
20
|
export declare function sha256(dataToHash: Array<number>): Array<number>
|
|
21
21
|
export declare function sha256Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
22
|
+
export declare function blake2Sha512(dataToHash: Array<number>): Array<number>
|
|
23
|
+
export declare function blake2Sha512Threadpool(dataToHash: Array<number>): Array<number>
|
|
24
|
+
export declare function blake2Sha512Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
25
|
+
export declare function blake2Sha512VerifyThreadpool(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
26
|
+
export declare function blake2Sha256(dataToHash: Array<number>): Array<number>
|
|
27
|
+
export declare function blake2Sha256Threadpool(dataToHash: Array<number>): Array<number>
|
|
28
|
+
export declare function blake2Sha256Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
29
|
+
export declare function blake2Sha256VerifyThreadpool(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
|
|
22
30
|
export declare function x25519GenerateSecretAndPublicKey(): CASx25519SecretPublicKeyResult
|
|
23
31
|
export declare function x25519DiffieHellman(mySecretKey: Array<number>, usersPublicKey: Array<number>): Array<number>
|
|
24
32
|
export declare function aesNonce(): Array<number>
|
package/index.node
CHANGED
|
Binary file
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { IHasherBase } from "./hasher-base";
|
|
2
|
+
export declare class Blake2Wrapper implements IHasherBase {
|
|
3
|
+
/**
|
|
4
|
+
* Hashes the input data using Blake2b 512
|
|
5
|
+
* @param dataToHash The data to hash
|
|
6
|
+
* @returns The hashed output
|
|
7
|
+
*/
|
|
8
|
+
hash512(dataToHash: number[]): number[];
|
|
9
|
+
/**
|
|
10
|
+
* Hashes the input data using Blake2b 512 in a thread pool
|
|
11
|
+
* @param dataToHash The data to hash
|
|
12
|
+
* @returns The hashed output
|
|
13
|
+
*/
|
|
14
|
+
hash512Threadpool(dataToHash: number[]): number[];
|
|
15
|
+
/**
|
|
16
|
+
* Verifies the input data against the hashed output using Blake2b 512
|
|
17
|
+
* @param dataToHash The data to hash
|
|
18
|
+
* @param dataToVerify The data to verify
|
|
19
|
+
* @returns True if the verification is successful, false otherwise
|
|
20
|
+
*/
|
|
21
|
+
verify512(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Verifies the input data against the hashed output using Blake2b 512 in a thread pool
|
|
24
|
+
* @param dataToHash The data to hash
|
|
25
|
+
* @param dataToVerify The data to verify
|
|
26
|
+
* @returns True if the verification is successful, false otherwise
|
|
27
|
+
*/
|
|
28
|
+
verify512Threadpool(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Hashes the input data using Blake2b 256
|
|
31
|
+
* @param dataToHash The data to hash
|
|
32
|
+
* @returns The hashed output
|
|
33
|
+
*/
|
|
34
|
+
hash256(dataToHash: number[]): number[];
|
|
35
|
+
/**
|
|
36
|
+
* Hashes the input data using Blake2b 256 in a thread pool
|
|
37
|
+
* @param dataToHash The data to hash
|
|
38
|
+
* @returns The hashed output
|
|
39
|
+
*/
|
|
40
|
+
hash256Threadpool(dataToHash: number[]): number[];
|
|
41
|
+
/**
|
|
42
|
+
* Verifies the input data against the hashed output using Blake2b 256
|
|
43
|
+
* @param dataToHash The data to hash
|
|
44
|
+
* @param dataToVerify The data to verify
|
|
45
|
+
* @returns True if the verification is successful, false otherwise
|
|
46
|
+
*/
|
|
47
|
+
verify256(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Verifies the input data against the hashed output using Blake2b 256 in a thread pool
|
|
50
|
+
* @param dataToHash The data to hash
|
|
51
|
+
* @param dataToVerify The data to verify
|
|
52
|
+
* @returns True if the verification is successful, false otherwise
|
|
53
|
+
*/
|
|
54
|
+
verify256Threadpool(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
55
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Blake2Wrapper = void 0;
|
|
4
|
+
const index_1 = require("../../index");
|
|
5
|
+
class Blake2Wrapper {
|
|
6
|
+
/**
|
|
7
|
+
* Hashes the input data using Blake2b 512
|
|
8
|
+
* @param dataToHash The data to hash
|
|
9
|
+
* @returns The hashed output
|
|
10
|
+
*/
|
|
11
|
+
hash512(dataToHash) {
|
|
12
|
+
return (0, index_1.blake2Sha512)(dataToHash);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Hashes the input data using Blake2b 512 in a thread pool
|
|
16
|
+
* @param dataToHash The data to hash
|
|
17
|
+
* @returns The hashed output
|
|
18
|
+
*/
|
|
19
|
+
hash512Threadpool(dataToHash) {
|
|
20
|
+
return (0, index_1.blake2Sha512Threadpool)(dataToHash);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Verifies the input data against the hashed output using Blake2b 512
|
|
24
|
+
* @param dataToHash The data to hash
|
|
25
|
+
* @param dataToVerify The data to verify
|
|
26
|
+
* @returns True if the verification is successful, false otherwise
|
|
27
|
+
*/
|
|
28
|
+
verify512(dataToHash, dataToVerify) {
|
|
29
|
+
return (0, index_1.blake2Sha512Verify)(dataToHash, dataToVerify);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Verifies the input data against the hashed output using Blake2b 512 in a thread pool
|
|
33
|
+
* @param dataToHash The data to hash
|
|
34
|
+
* @param dataToVerify The data to verify
|
|
35
|
+
* @returns True if the verification is successful, false otherwise
|
|
36
|
+
*/
|
|
37
|
+
verify512Threadpool(dataToHash, dataToVerify) {
|
|
38
|
+
return (0, index_1.blake2Sha512VerifyThreadpool)(dataToHash, dataToVerify);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Hashes the input data using Blake2b 256
|
|
42
|
+
* @param dataToHash The data to hash
|
|
43
|
+
* @returns The hashed output
|
|
44
|
+
*/
|
|
45
|
+
hash256(dataToHash) {
|
|
46
|
+
return (0, index_1.blake2Sha256)(dataToHash);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Hashes the input data using Blake2b 256 in a thread pool
|
|
50
|
+
* @param dataToHash The data to hash
|
|
51
|
+
* @returns The hashed output
|
|
52
|
+
*/
|
|
53
|
+
hash256Threadpool(dataToHash) {
|
|
54
|
+
return (0, index_1.blake2Sha256Threadpool)(dataToHash);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Verifies the input data against the hashed output using Blake2b 256
|
|
58
|
+
* @param dataToHash The data to hash
|
|
59
|
+
* @param dataToVerify The data to verify
|
|
60
|
+
* @returns True if the verification is successful, false otherwise
|
|
61
|
+
*/
|
|
62
|
+
verify256(dataToHash, dataToVerify) {
|
|
63
|
+
return (0, index_1.blake2Sha256Verify)(dataToHash, dataToVerify);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Verifies the input data against the hashed output using Blake2b 256 in a thread pool
|
|
67
|
+
* @param dataToHash The data to hash
|
|
68
|
+
* @param dataToVerify The data to verify
|
|
69
|
+
* @returns True if the verification is successful, false otherwise
|
|
70
|
+
*/
|
|
71
|
+
verify256Threadpool(dataToHash, dataToVerify) {
|
|
72
|
+
return (0, index_1.blake2Sha256VerifyThreadpool)(dataToHash, dataToVerify);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.Blake2Wrapper = Blake2Wrapper;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HasherFactory = void 0;
|
|
4
|
+
const blake2_wrapper_1 = require("./blake2-wrapper");
|
|
5
|
+
const hasher_type_1 = require("./hasher-type");
|
|
4
6
|
const sha_wrapper_1 = require("./sha-wrapper");
|
|
5
7
|
class HasherFactory {
|
|
6
8
|
/**
|
|
@@ -11,6 +13,8 @@ class HasherFactory {
|
|
|
11
13
|
getHasher(type) {
|
|
12
14
|
let result = new sha_wrapper_1.SHAWrapper();
|
|
13
15
|
switch (type) {
|
|
16
|
+
case hasher_type_1.HasherType.Blake2:
|
|
17
|
+
result = new blake2_wrapper_1.Blake2Wrapper();
|
|
14
18
|
}
|
|
15
19
|
return result;
|
|
16
20
|
}
|
package/lib/hashers/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HasherFactory } from "./hasher-factory";
|
|
2
2
|
import { HasherType } from "./hasher-type";
|
|
3
3
|
import { SHAWrapper } from "./sha-wrapper";
|
|
4
|
-
|
|
4
|
+
import { Blake2Wrapper } from "./blake2-wrapper";
|
|
5
|
+
export { SHAWrapper, HasherFactory, HasherType, Blake2Wrapper };
|
package/lib/hashers/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HasherType = exports.HasherFactory = exports.SHAWrapper = void 0;
|
|
3
|
+
exports.Blake2Wrapper = exports.HasherType = exports.HasherFactory = exports.SHAWrapper = void 0;
|
|
4
4
|
const hasher_factory_1 = require("./hasher-factory");
|
|
5
5
|
Object.defineProperty(exports, "HasherFactory", { enumerable: true, get: function () { return hasher_factory_1.HasherFactory; } });
|
|
6
6
|
const hasher_type_1 = require("./hasher-type");
|
|
7
7
|
Object.defineProperty(exports, "HasherType", { enumerable: true, get: function () { return hasher_type_1.HasherType; } });
|
|
8
8
|
const sha_wrapper_1 = require("./sha-wrapper");
|
|
9
9
|
Object.defineProperty(exports, "SHAWrapper", { enumerable: true, get: function () { return sha_wrapper_1.SHAWrapper; } });
|
|
10
|
+
const blake2_wrapper_1 = require("./blake2-wrapper");
|
|
11
|
+
Object.defineProperty(exports, "Blake2Wrapper", { enumerable: true, get: function () { return blake2_wrapper_1.Blake2Wrapper; } });
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cas-typescript-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.32",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "
|
|
9
|
-
"node:test": "mocha -r ts-node/register ./test-ts/**/*.ts --timeout 20000 --recursive",
|
|
8
|
+
"test": "npm run rust:test && npm run build && npm run node:test",
|
|
9
|
+
"node:test": "mocha -r ts-node/register ./test-ts/**/*.test.spec.ts --timeout 20000 --recursive",
|
|
10
10
|
"rust:test": "cargo test --release",
|
|
11
11
|
"build": "npm run build:rust && rimraf lib && tsc",
|
|
12
12
|
"build:rust": "napi build --release",
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@napi-rs/cli": "^2.18.4",
|
|
32
|
-
"@types/chai": "^4.3.
|
|
33
|
-
"@types/mocha": "^10.0.
|
|
34
|
-
"@types/node-fetch": "^2.6.
|
|
35
|
-
"chai": "^4.
|
|
36
|
-
"mocha": "^10.2
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
32
|
+
"@types/chai": "^4.3.20",
|
|
33
|
+
"@types/mocha": "^10.0.10",
|
|
34
|
+
"@types/node-fetch": "^2.6.12",
|
|
35
|
+
"chai": "^4.5.0",
|
|
36
|
+
"mocha": "^10.8.2",
|
|
37
|
+
"rimraf": "^6.0.1",
|
|
38
|
+
"ts-node": "^10.9.2",
|
|
39
|
+
"typescript": "^5.8.3"
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -5,29 +5,45 @@ 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]
|
|
12
12
|
pub fn sha_256_ed25519_digital_signature_verify(public_key: Vec<u8>, data_to_verify: Vec<u8>, signature: Vec<u8>) -> bool {
|
|
13
|
-
|
|
13
|
+
if public_key.len() != 32 || signature.len() != 64 {
|
|
14
|
+
return false;
|
|
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)
|
|
14
21
|
}
|
|
15
22
|
|
|
23
|
+
|
|
16
24
|
#[test]
|
|
17
25
|
fn sha_256_ed25519_test() {
|
|
18
26
|
let key_size: u32 = 1024;
|
|
19
|
-
let data_to_sign = b"GetTheseBytes"
|
|
20
|
-
let signature_result: CASSHAED25519DalekDigitalSignatureResult = SHA256ED25519DigitalSignature::digital_signature_ed25519(data_to_sign.clone()).into();
|
|
21
|
-
let
|
|
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);
|
|
22
34
|
assert_eq!(is_verified, true);
|
|
23
35
|
}
|
|
24
36
|
|
|
25
37
|
#[test]
|
|
26
38
|
fn sha_512_ed25519_test_fail() {
|
|
27
39
|
let key_size: u32 = 1024;
|
|
28
|
-
let data_to_sign = b"GetTheseBytes"
|
|
29
|
-
let signature_result: CASSHAED25519DalekDigitalSignatureResult = SHA256ED25519DigitalSignature::digital_signature_ed25519(data_to_sign.clone()).into();
|
|
30
|
-
let not_original_data = b"NOtTHoseBytes"
|
|
31
|
-
let
|
|
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
48
|
assert_eq!(is_verified, false);
|
|
33
49
|
}
|
|
@@ -7,19 +7,25 @@ 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
|
-
|
|
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
|
+
return <SHA512ED25519DigitalSignature as ED25519DigitalSignature>::digital_signature_ed25519_verify(
|
|
18
|
+
public_key_array,
|
|
19
|
+
&data_to_verify,
|
|
20
|
+
signature_array,
|
|
21
|
+
);
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
#[test]
|
|
19
25
|
fn sha_512_ed25519_test() {
|
|
20
26
|
let key_size: u32 = 1024;
|
|
21
|
-
let data_to_sign = b"GetTheseBytes"
|
|
22
|
-
let signature_result: SHAED25519DalekDigitalSignatureResult = <SHA512ED25519DigitalSignature as ED25519DigitalSignature>::digital_signature_ed25519(data_to_sign.clone());
|
|
27
|
+
let data_to_sign = b"GetTheseBytes";
|
|
28
|
+
let signature_result: SHAED25519DalekDigitalSignatureResult = <SHA512ED25519DigitalSignature as ED25519DigitalSignature>::digital_signature_ed25519(&data_to_sign.clone());
|
|
23
29
|
let is_verified: bool = SHA512ED25519DigitalSignature::digital_signature_ed25519_verify(signature_result.public_key, data_to_sign, signature_result.signature);
|
|
24
30
|
assert_eq!(is_verified, true);
|
|
25
31
|
}
|
|
@@ -27,9 +33,15 @@ fn sha_512_ed25519_test() {
|
|
|
27
33
|
#[test]
|
|
28
34
|
fn sha_512_ed25519_test_fail() {
|
|
29
35
|
let key_size: u32 = 1024;
|
|
30
|
-
let data_to_sign = b"GetTheseBytes"
|
|
31
|
-
let signature_result: CASSHAED25519DalekDigitalSignatureResult = <SHA512ED25519DigitalSignature as ED25519DigitalSignature>::digital_signature_ed25519(data_to_sign.clone()).into();
|
|
36
|
+
let data_to_sign = b"GetTheseBytes";
|
|
37
|
+
let signature_result: CASSHAED25519DalekDigitalSignatureResult = <SHA512ED25519DigitalSignature as ED25519DigitalSignature>::digital_signature_ed25519(&data_to_sign.clone()).into();
|
|
32
38
|
let not_original_data = b"NOtTHoseBytes".to_vec();
|
|
33
|
-
let
|
|
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
|
+
let is_verified: bool = SHA512ED25519DigitalSignature::digital_signature_ed25519_verify(
|
|
42
|
+
public_key_array,
|
|
43
|
+
¬_original_data,
|
|
44
|
+
signature_array,
|
|
45
|
+
);
|
|
34
46
|
assert_eq!(is_verified, false);
|
|
35
47
|
}
|
|
@@ -10,8 +10,8 @@ pub struct CASSHAED25519DalekDigitalSignatureResult {
|
|
|
10
10
|
impl From<SHAED25519DalekDigitalSignatureResult> for CASSHAED25519DalekDigitalSignatureResult {
|
|
11
11
|
fn from(value: SHAED25519DalekDigitalSignatureResult) -> Self {
|
|
12
12
|
CASSHAED25519DalekDigitalSignatureResult {
|
|
13
|
-
public_key: value.public_key,
|
|
14
|
-
signature: value.signature
|
|
13
|
+
public_key: value.public_key.to_vec(),
|
|
14
|
+
signature: value.signature.to_vec()
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
use cas_lib::hashers::{blake2::CASBlake2, cas_hasher::CASHasher};
|
|
2
|
+
use napi_derive::napi;
|
|
3
|
+
|
|
4
|
+
#[napi]
|
|
5
|
+
pub fn blake2_sha_512(data_to_hash: Vec<u8>) -> Vec<u8> {
|
|
6
|
+
return CASBlake2::hash_512(data_to_hash);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
#[napi]
|
|
10
|
+
pub fn blake2_sha_512_threadpool(data_to_hash: Vec<u8>) -> Vec<u8> {
|
|
11
|
+
return CASBlake2::hash_512_threadpool(data_to_hash);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
#[napi]
|
|
15
|
+
pub fn blake2_sha_512_verify(data_to_hash: Vec<u8>, data_to_verify: Vec<u8>) -> bool {
|
|
16
|
+
return CASBlake2::verify_512(data_to_hash, data_to_verify);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
#[napi]
|
|
20
|
+
pub fn blake2_sha_512_verify_threadpool(data_to_hash: Vec<u8>, data_to_verify: Vec<u8>) -> bool {
|
|
21
|
+
return CASBlake2::verify_512_threadpool(data_to_hash, data_to_verify);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
#[napi]
|
|
25
|
+
pub fn blake2_sha_256(data_to_hash: Vec<u8>) -> Vec<u8> {
|
|
26
|
+
return CASBlake2::hash_256(data_to_hash);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
#[napi]
|
|
30
|
+
pub fn blake2_sha_256_threadpool(data_to_hash: Vec<u8>) -> Vec<u8> {
|
|
31
|
+
return CASBlake2::hash_256_threadpool(data_to_hash);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#[napi]
|
|
35
|
+
pub fn blake2_sha_256_verify(data_to_hash: Vec<u8>, data_to_verify: Vec<u8>) -> bool {
|
|
36
|
+
return CASBlake2::verify_256(data_to_hash, data_to_verify);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
#[napi]
|
|
40
|
+
pub fn blake2_sha_256_verify_threadpool(data_to_hash: Vec<u8>, data_to_verify: Vec<u8>) -> bool {
|
|
41
|
+
return CASBlake2::verify_256_threadpool(data_to_hash, data_to_verify);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
#[test]
|
|
45
|
+
pub fn blake2_sha_512_test() {
|
|
46
|
+
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
47
|
+
let hashed_data = blake2_sha_512(data_to_hash.clone());
|
|
48
|
+
assert_ne!(true, hashed_data.eq(&data_to_hash));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
#[test]
|
|
52
|
+
pub fn blake2_sha_512_threadpool_test() {
|
|
53
|
+
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
54
|
+
let hashed_data = blake2_sha_512_threadpool(data_to_hash.clone());
|
|
55
|
+
assert_ne!(true, hashed_data.eq(&data_to_hash));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
#[test]
|
|
59
|
+
pub fn blake2_sha_512_verify_test() {
|
|
60
|
+
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
61
|
+
let hashed_data = blake2_sha_512(data_to_hash.clone());
|
|
62
|
+
let data_to_verify = "NotMyDataToHash".as_bytes().to_vec();
|
|
63
|
+
assert_ne!(true, blake2_sha_512_verify_threadpool(data_to_hash, data_to_verify));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
#[test]
|
|
67
|
+
pub fn blake2_sha_512_threadpool_verify_test() {
|
|
68
|
+
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
69
|
+
let hashed_data = blake2_sha_512_threadpool(data_to_hash.clone());
|
|
70
|
+
let data_to_verify = "NotMyDataToHash".as_bytes().to_vec();
|
|
71
|
+
assert_ne!(true, blake2_sha_512_verify_threadpool(data_to_hash, data_to_verify));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
#[test]
|
|
75
|
+
pub fn blake2_sha_512_verify_fail_test() {
|
|
76
|
+
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
77
|
+
let _hashed_data = blake2_sha_512(data_to_hash.clone());
|
|
78
|
+
let data_to_verify = "NotMyDataToHash2".as_bytes().to_vec();
|
|
79
|
+
assert_ne!(true, blake2_sha_512_verify(data_to_hash, data_to_verify));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
#[test]
|
|
83
|
+
pub fn blake2_sha_512_verify_threadpool_fail_test() {
|
|
84
|
+
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
85
|
+
let _hashed_data = blake2_sha_512_threadpool(data_to_hash.clone());
|
|
86
|
+
let data_to_verify = "NotMyDataToHash2".as_bytes().to_vec();
|
|
87
|
+
assert_ne!(true, blake2_sha_512_verify_threadpool(data_to_hash, data_to_verify));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#[test]
|
|
91
|
+
pub fn blake2_sha_256_test() {
|
|
92
|
+
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
93
|
+
let hashed_data = blake2_sha_256(data_to_hash.clone());
|
|
94
|
+
assert_ne!(true, hashed_data.eq(&data_to_hash));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
#[test]
|
|
98
|
+
pub fn blake2_sha_256_verify_test() {
|
|
99
|
+
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
100
|
+
let _hashed_data = blake2_sha_256(data_to_hash.clone());
|
|
101
|
+
let data_to_verify = "NotMyDataToHash".as_bytes().to_vec();
|
|
102
|
+
assert_ne!(true, blake2_sha_256_verify(data_to_hash, data_to_verify));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
#[test]
|
|
106
|
+
pub fn blake2_sha_256_verify_threadpool_test() {
|
|
107
|
+
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
108
|
+
let _hashed_data = blake2_sha_256_threadpool(data_to_hash.clone());
|
|
109
|
+
let data_to_verify = "NotMyDataToHash".as_bytes().to_vec();
|
|
110
|
+
assert_ne!(true, blake2_sha_256_verify_threadpool(data_to_hash, data_to_verify));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
#[test]
|
|
114
|
+
pub fn blake2_sha_256_verify_fail_test() {
|
|
115
|
+
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
116
|
+
let _hashed_data = blake2_sha_256(data_to_hash.clone());
|
|
117
|
+
let data_to_verify = "NotMyDataToHash2".as_bytes().to_vec();
|
|
118
|
+
assert_ne!(true, blake2_sha_256_verify(data_to_hash, data_to_verify));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
#[test]
|
|
122
|
+
pub fn blake2_sha_256_verify_threadpool_fail_test() {
|
|
123
|
+
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
124
|
+
let _hashed_data = blake2_sha_256_threadpool(data_to_hash.clone());
|
|
125
|
+
let data_to_verify = "NotMyDataToHash2".as_bytes().to_vec();
|
|
126
|
+
assert_ne!(true, blake2_sha_256_verify_threadpool(data_to_hash, data_to_verify));
|
|
127
|
+
}
|
package/src/hashers/sha.rs
CHANGED
|
@@ -39,7 +39,7 @@ pub fn sha_512_verify_test() {
|
|
|
39
39
|
#[test]
|
|
40
40
|
pub fn sha_512_verify_fail_test() {
|
|
41
41
|
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
42
|
-
let
|
|
42
|
+
let _hashed_data = sha_512(data_to_hash.clone());
|
|
43
43
|
let data_to_verify = "NotMyDataToHash2".as_bytes().to_vec();
|
|
44
44
|
assert_ne!(true, sha_512_verify(data_to_hash, data_to_verify));
|
|
45
45
|
}
|
|
@@ -54,7 +54,7 @@ pub fn sha_256_test() {
|
|
|
54
54
|
#[test]
|
|
55
55
|
pub fn sha_256_verify_test() {
|
|
56
56
|
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
57
|
-
let
|
|
57
|
+
let _hashed_data = sha_256(data_to_hash.clone());
|
|
58
58
|
let data_to_verify = "NotMyDataToHash".as_bytes().to_vec();
|
|
59
59
|
assert_ne!(true, sha_256_verify(data_to_hash, data_to_verify));
|
|
60
60
|
}
|
|
@@ -62,7 +62,7 @@ pub fn sha_256_verify_test() {
|
|
|
62
62
|
#[test]
|
|
63
63
|
pub fn sha_256_verify_fail_test() {
|
|
64
64
|
let data_to_hash = "NotMyDataToHash".as_bytes().to_vec();
|
|
65
|
-
let
|
|
65
|
+
let _hashed_data = sha_256(data_to_hash.clone());
|
|
66
66
|
let data_to_verify = "NotMyDataToHash2".as_bytes().to_vec();
|
|
67
67
|
assert_ne!(true, sha_256_verify(data_to_hash, data_to_verify));
|
|
68
68
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
use cas_lib::key_exchange::x25519::
|
|
1
|
+
use cas_lib::key_exchange::x25519::X25519SecretPublicKeyResult;
|
|
2
2
|
use napi_derive::napi;
|
|
3
3
|
|
|
4
4
|
#[napi(constructor)]
|
|
@@ -7,8 +7,8 @@ pub struct CASx25519SecretPublicKeyResult {
|
|
|
7
7
|
pub secret_key: Vec<u8>,
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
impl From<
|
|
11
|
-
fn from(value:
|
|
10
|
+
impl From<X25519SecretPublicKeyResult> for CASx25519SecretPublicKeyResult {
|
|
11
|
+
fn from(value: X25519SecretPublicKeyResult) -> Self {
|
|
12
12
|
CASx25519SecretPublicKeyResult {
|
|
13
13
|
public_key: value.public_key,
|
|
14
14
|
secret_key: value.secret_key
|
|
@@ -11,7 +11,7 @@ pub fn x25519_generate_secret_and_public_key() -> CASx25519SecretPublicKeyResult
|
|
|
11
11
|
|
|
12
12
|
#[napi]
|
|
13
13
|
pub fn x25519_diffie_hellman(my_secret_key: Vec<u8>, users_public_key: Vec<u8>) -> Vec<u8> {
|
|
14
|
-
return <X25519 as CASKeyExchange>::diffie_hellman(my_secret_key, users_public_key);
|
|
14
|
+
return <X25519 as CASKeyExchange>::diffie_hellman(my_secret_key, users_public_key).to_vec();
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
#[test]
|
package/src/lib.rs
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
|
|
2
2
|
use napi_derive::napi;
|
|
3
3
|
use cas_lib::password_hashers::argon2::CASArgon;
|
|
4
|
-
use cas_lib::password_hashers::cas_password_hasher::CASPasswordHasher;
|
|
5
4
|
|
|
6
5
|
#[napi]
|
|
7
6
|
pub fn argon2_hash(password: String) -> String {
|
|
8
|
-
return
|
|
7
|
+
return CASArgon::hash_password(password);
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
#[napi]
|
|
12
11
|
pub fn argon2_hash_thread_pool(password: String) -> String {
|
|
13
|
-
return
|
|
12
|
+
return CASArgon::hash_password_threadpool(password);
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
#[napi]
|
|
17
16
|
pub fn argon2_verify(hashed_password: String, password_to_verify: String) -> bool {
|
|
18
|
-
return
|
|
17
|
+
return CASArgon::verify_password(hashed_password, password_to_verify);
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
#[napi]
|
|
22
21
|
pub fn argon2_verify_threadpool(hashed_password: String, password_to_verify: String) -> bool {
|
|
23
|
-
return
|
|
22
|
+
return CASArgon::verify_password_threadpool(hashed_password, password_to_verify);
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
#[test]
|
|
@@ -9,7 +9,7 @@ pub fn bcrypt_hash(password_to_hash: String) -> String {
|
|
|
9
9
|
|
|
10
10
|
#[napi]
|
|
11
11
|
pub fn bcrypt_hash_threadpool(password_to_hash: String) -> String {
|
|
12
|
-
return <CASBCrypt as CASPasswordHasher>::
|
|
12
|
+
return <CASBCrypt as CASPasswordHasher>::hash_password_threadpool(password_to_hash);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
#[napi]
|
|
@@ -13,7 +13,7 @@ pub fn scrypt_verify(hashed_password: String, password_to_verify: String) -> boo
|
|
|
13
13
|
|
|
14
14
|
#[napi]
|
|
15
15
|
pub fn scrypt_hash_threadpool(password_to_hash: String) -> String {
|
|
16
|
-
return <CASScrypt as CASPasswordHasher>::
|
|
16
|
+
return <CASScrypt as CASPasswordHasher>::hash_password_threadpool(password_to_hash);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
#[napi]
|
|
@@ -4,7 +4,7 @@ use napi_derive::napi;
|
|
|
4
4
|
|
|
5
5
|
#[napi]
|
|
6
6
|
pub fn ascon128_key_generate() -> Vec<u8> {
|
|
7
|
-
return <AsconAead as CASAsconAead>::generate_key();
|
|
7
|
+
return <AsconAead as CASAsconAead>::generate_key().to_vec();
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
#[test]
|
|
@@ -15,7 +15,7 @@ fn test_ascon128_key_generate() {
|
|
|
15
15
|
|
|
16
16
|
#[napi]
|
|
17
17
|
pub fn ascon128_nonce_generate() -> Vec<u8> {
|
|
18
|
-
return <AsconAead as CASAsconAead>::generate_nonce();
|
|
18
|
+
return <AsconAead as CASAsconAead>::generate_nonce().to_vec();
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
#[test]
|
|
@@ -26,29 +26,45 @@ 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
|
-
|
|
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);
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
#[test]
|
|
33
35
|
pub fn test_ascon128_encrypt() {
|
|
34
36
|
let key = <AsconAead as CASAsconAead>::generate_key();
|
|
35
37
|
let nonce = <AsconAead as CASAsconAead>::generate_nonce();
|
|
36
|
-
let plaintext = b"Hello, World!"
|
|
37
|
-
let ciphertext = ascon128_encrypt(
|
|
38
|
-
|
|
38
|
+
let plaintext = b"Hello, World!";
|
|
39
|
+
let ciphertext = ascon128_encrypt(
|
|
40
|
+
key.clone().to_vec(),
|
|
41
|
+
nonce.clone().to_vec(),
|
|
42
|
+
plaintext.to_vec(),
|
|
43
|
+
);
|
|
44
|
+
assert_ne!(ciphertext, plaintext.to_vec());
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
#[napi]
|
|
42
48
|
pub fn ascon128_decrypt(key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
|
|
43
|
-
|
|
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);
|
|
44
52
|
}
|
|
45
53
|
|
|
46
54
|
#[test]
|
|
47
55
|
pub fn test_ascon128_decrypt() {
|
|
48
56
|
let key = <AsconAead as CASAsconAead>::generate_key();
|
|
49
57
|
let nonce = <AsconAead as CASAsconAead>::generate_nonce();
|
|
50
|
-
let plaintext = b"Hello, World!"
|
|
51
|
-
let ciphertext = ascon128_encrypt(
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
let plaintext = b"Hello, World!";
|
|
59
|
+
let ciphertext = ascon128_encrypt(
|
|
60
|
+
key.clone().to_vec(),
|
|
61
|
+
nonce.clone().to_vec(),
|
|
62
|
+
plaintext.to_vec(),
|
|
63
|
+
);
|
|
64
|
+
let decrypted = ascon128_decrypt(
|
|
65
|
+
key.clone().to_vec(),
|
|
66
|
+
nonce.clone().to_vec(),
|
|
67
|
+
ciphertext.clone(),
|
|
68
|
+
);
|
|
69
|
+
assert_eq!(decrypted, plaintext.to_vec());
|
|
54
70
|
}
|
package/src/symmetric/aes.rs
CHANGED
|
@@ -1,55 +1,65 @@
|
|
|
1
|
-
use cas_lib::symmetric::{aes::{CASAES128, CASAES256}, cas_symmetric_encryption::
|
|
1
|
+
use cas_lib::symmetric::{aes::{CASAES128, CASAES256}, cas_symmetric_encryption::{CASAES128Encryption, CASAES256Encryption}};
|
|
2
2
|
use napi_derive::napi;
|
|
3
3
|
|
|
4
4
|
use super::types::CASAesKeyFromX25519SharedSecret;
|
|
5
5
|
|
|
6
6
|
#[napi]
|
|
7
7
|
pub fn aes_nonce() -> Vec<u8> {
|
|
8
|
-
return <CASAES256 as
|
|
8
|
+
return <CASAES256 as CASAES256Encryption>::generate_nonce().to_vec();
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
#[napi]
|
|
12
12
|
pub fn aes128_key() -> Vec<u8> {
|
|
13
|
-
return <CASAES128 as
|
|
13
|
+
return <CASAES128 as CASAES128Encryption>::generate_key().to_vec();
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
#[napi]
|
|
17
17
|
pub fn aes256_key() -> Vec<u8> {
|
|
18
|
-
return <CASAES256 as
|
|
18
|
+
return <CASAES256 as CASAES256Encryption>::generate_key().to_vec();
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
#[napi]
|
|
22
22
|
pub fn aes128_encrypt(aes_key: Vec<u8>, nonce: Vec<u8>, plaintext: Vec<u8>) -> Vec<u8> {
|
|
23
|
-
|
|
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)
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
#[napi]
|
|
27
29
|
pub fn aes128_decrypt(aes_key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
|
|
28
|
-
|
|
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)
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
#[napi]
|
|
32
36
|
pub fn aes256_encrypt(aes_key: Vec<u8>, nonce: Vec<u8>, plaintext: Vec<u8>) -> Vec<u8> {
|
|
33
|
-
|
|
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)
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
#[napi]
|
|
37
43
|
pub fn aes256_decrypt(aes_key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
|
|
38
|
-
|
|
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)
|
|
39
47
|
}
|
|
40
48
|
|
|
41
49
|
#[napi]
|
|
42
50
|
pub fn aes_256_key_from_x25519_shared_secret(
|
|
43
51
|
shared_secret: Vec<u8>,
|
|
44
52
|
) -> CASAesKeyFromX25519SharedSecret {
|
|
45
|
-
|
|
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();
|
|
46
55
|
}
|
|
47
56
|
|
|
48
57
|
#[napi]
|
|
49
58
|
pub fn aes_128_key_from_x25519_shared_secret(
|
|
50
59
|
shared_secret: Vec<u8>,
|
|
51
60
|
) -> CASAesKeyFromX25519SharedSecret {
|
|
52
|
-
|
|
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();
|
|
53
63
|
}
|
|
54
64
|
|
|
55
65
|
#[test]
|
package/src/symmetric/types.rs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
use cas_lib::symmetric::cas_symmetric_encryption::{Aes128KeyFromX25519SharedSecret, Aes256KeyFromX25519SharedSecret};
|
|
2
3
|
use napi_derive::napi;
|
|
3
4
|
|
|
4
5
|
#[napi(constructor)]
|
|
@@ -7,11 +8,20 @@ pub struct CASAesKeyFromX25519SharedSecret {
|
|
|
7
8
|
pub aes_nonce: Vec<u8>,
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
impl From<
|
|
11
|
-
fn from(value:
|
|
11
|
+
impl From<Aes128KeyFromX25519SharedSecret> for CASAesKeyFromX25519SharedSecret {
|
|
12
|
+
fn from(value: Aes128KeyFromX25519SharedSecret) -> Self {
|
|
13
|
+
CASAesKeyFromX25519SharedSecret {
|
|
14
|
+
aes_key: value.aes_key.to_vec(),
|
|
15
|
+
aes_nonce: value.aes_nonce.to_vec()
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
impl From<Aes256KeyFromX25519SharedSecret> for CASAesKeyFromX25519SharedSecret {
|
|
21
|
+
fn from(value: Aes256KeyFromX25519SharedSecret) -> Self {
|
|
12
22
|
CASAesKeyFromX25519SharedSecret {
|
|
13
|
-
aes_key: value.aes_key,
|
|
14
|
-
aes_nonce: value.aes_nonce
|
|
23
|
+
aes_key: value.aes_key.to_vec(),
|
|
24
|
+
aes_nonce: value.aes_nonce.to_vec()
|
|
15
25
|
}
|
|
16
26
|
}
|
|
17
27
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { blake2Sha512Verify, blake2Sha256Verify, blake2Sha256, blake2Sha512, blake2Sha512Threadpool, blake2Sha512VerifyThreadpool, blake2Sha256Threadpool, blake2Sha256VerifyThreadpool } from "../../index";
|
|
2
|
+
import { IHasherBase } from "./hasher-base";
|
|
3
|
+
|
|
4
|
+
export class Blake2Wrapper implements IHasherBase {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hashes the input data using Blake2b 512
|
|
8
|
+
* @param dataToHash The data to hash
|
|
9
|
+
* @returns The hashed output
|
|
10
|
+
*/
|
|
11
|
+
hash512(dataToHash: number[]): number[] {
|
|
12
|
+
return blake2Sha512(dataToHash);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Hashes the input data using Blake2b 512 in a thread pool
|
|
17
|
+
* @param dataToHash The data to hash
|
|
18
|
+
* @returns The hashed output
|
|
19
|
+
*/
|
|
20
|
+
hash512Threadpool(dataToHash: number[]): number[] {
|
|
21
|
+
return blake2Sha512Threadpool(dataToHash);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Verifies the input data against the hashed output using Blake2b 512
|
|
26
|
+
* @param dataToHash The data to hash
|
|
27
|
+
* @param dataToVerify The data to verify
|
|
28
|
+
* @returns True if the verification is successful, false otherwise
|
|
29
|
+
*/
|
|
30
|
+
verify512(dataToHash: number[], dataToVerify: number[]): boolean {
|
|
31
|
+
return blake2Sha512Verify(dataToHash, dataToVerify);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Verifies the input data against the hashed output using Blake2b 512 in a thread pool
|
|
36
|
+
* @param dataToHash The data to hash
|
|
37
|
+
* @param dataToVerify The data to verify
|
|
38
|
+
* @returns True if the verification is successful, false otherwise
|
|
39
|
+
*/
|
|
40
|
+
verify512Threadpool(dataToHash: number[], dataToVerify: number[]): boolean {
|
|
41
|
+
return blake2Sha512VerifyThreadpool(dataToHash, dataToVerify);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Hashes the input data using Blake2b 256
|
|
46
|
+
* @param dataToHash The data to hash
|
|
47
|
+
* @returns The hashed output
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
hash256(dataToHash: number[]): number[] {
|
|
51
|
+
return blake2Sha256(dataToHash);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Hashes the input data using Blake2b 256 in a thread pool
|
|
56
|
+
* @param dataToHash The data to hash
|
|
57
|
+
* @returns The hashed output
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
hash256Threadpool(dataToHash: number[]): number[] {
|
|
61
|
+
return blake2Sha256Threadpool(dataToHash);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Verifies the input data against the hashed output using Blake2b 256
|
|
66
|
+
* @param dataToHash The data to hash
|
|
67
|
+
* @param dataToVerify The data to verify
|
|
68
|
+
* @returns True if the verification is successful, false otherwise
|
|
69
|
+
*/
|
|
70
|
+
verify256(dataToHash: number[], dataToVerify: number[]): boolean {
|
|
71
|
+
return blake2Sha256Verify(dataToHash, dataToVerify);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Verifies the input data against the hashed output using Blake2b 256 in a thread pool
|
|
76
|
+
* @param dataToHash The data to hash
|
|
77
|
+
* @param dataToVerify The data to verify
|
|
78
|
+
* @returns True if the verification is successful, false otherwise
|
|
79
|
+
*/
|
|
80
|
+
verify256Threadpool(dataToHash: number[], dataToVerify: number[]): boolean {
|
|
81
|
+
return blake2Sha256VerifyThreadpool(dataToHash, dataToVerify);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Blake2Wrapper } from "./blake2-wrapper";
|
|
1
2
|
import { HasherType } from "./hasher-type";
|
|
2
3
|
import { SHAWrapper } from "./sha-wrapper";
|
|
3
4
|
|
|
@@ -10,7 +11,8 @@ export class HasherFactory {
|
|
|
10
11
|
getHasher(type: HasherType): any {
|
|
11
12
|
let result: SHAWrapper = new SHAWrapper();
|
|
12
13
|
switch(type) {
|
|
13
|
-
|
|
14
|
+
case HasherType.Blake2:
|
|
15
|
+
result = new Blake2Wrapper();
|
|
14
16
|
}
|
|
15
17
|
return result;
|
|
16
18
|
}
|
package/src-ts/hashers/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HasherFactory } from "./hasher-factory";
|
|
2
2
|
import { HasherType } from "./hasher-type";
|
|
3
3
|
import { SHAWrapper } from "./sha-wrapper";
|
|
4
|
+
import { Blake2Wrapper } from "./blake2-wrapper";
|
|
4
5
|
|
|
5
|
-
export { SHAWrapper, HasherFactory, HasherType };
|
|
6
|
+
export { SHAWrapper, HasherFactory, HasherType, Blake2Wrapper };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assert } from "chai";
|
|
2
|
-
import { SHAWrapper } from "../src-ts/hashers/index";
|
|
2
|
+
import { Blake2Wrapper, SHAWrapper } from "../src-ts/hashers/index";
|
|
3
3
|
|
|
4
4
|
describe("SHA512 Tests", () => {
|
|
5
5
|
it("hash", () => {
|
|
@@ -37,17 +37,116 @@ describe("SHA512 Tests", () => {
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
describe("SHA256 Tests", () => {
|
|
40
|
+
it("hash", () => {
|
|
41
|
+
const wrapper = new SHAWrapper();
|
|
42
|
+
const tohashed: string = "This is my array to hash";
|
|
43
|
+
const encoder = new TextEncoder();
|
|
44
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
45
|
+
const hashed = wrapper.hash256(tohashBytes);
|
|
46
|
+
assert.notEqual(tohashBytes, hashed);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("verify pass", () => {
|
|
50
|
+
const wrapper = new SHAWrapper();
|
|
51
|
+
const tohashed: string = "This is my array to hash";
|
|
52
|
+
const encoder = new TextEncoder();
|
|
53
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
54
|
+
const hashed = wrapper.hash256(tohashBytes);
|
|
55
|
+
const toVerifyBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
56
|
+
const verified = wrapper.verify256(hashed, toVerifyBytes);
|
|
57
|
+
assert.equal(true, verified);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("verify fail", () => {
|
|
61
|
+
const wrapper = new SHAWrapper();
|
|
62
|
+
const tohashed: string = "This is my array to hash";
|
|
63
|
+
const encoder = new TextEncoder();
|
|
64
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
65
|
+
const hashed = wrapper.hash256(tohashBytes);
|
|
66
|
+
const toVerify = "This Is Not The Same";
|
|
67
|
+
const toVerifyBytes: Array<number> = Array.from(encoder.encode(toVerify));
|
|
68
|
+
const verified = wrapper.verify256(hashed, toVerifyBytes);
|
|
69
|
+
assert.equal(false, verified);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("Blake2 512", () => {
|
|
74
|
+
it("hash", () => {
|
|
75
|
+
const wrapper = new Blake2Wrapper();
|
|
76
|
+
const tohashed: string = "This is my array to hash";
|
|
77
|
+
const encoder = new TextEncoder();
|
|
78
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
79
|
+
const hashed = wrapper.hash512(tohashBytes);
|
|
80
|
+
assert.notEqual(tohashBytes, hashed);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("verify pass", () => {
|
|
84
|
+
const wrapper = new Blake2Wrapper();
|
|
85
|
+
const tohashed: string = "This is my array to hash";
|
|
86
|
+
const encoder = new TextEncoder();
|
|
87
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
88
|
+
const hashed = wrapper.hash512(tohashBytes);
|
|
89
|
+
const toVerifyBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
90
|
+
const verified = wrapper.verify512(hashed, toVerifyBytes);
|
|
91
|
+
assert.equal(true, verified);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("verify fail", () => {
|
|
95
|
+
const wrapper = new Blake2Wrapper();
|
|
96
|
+
const tohashed: string = "This is my array to hash";
|
|
97
|
+
const encoder = new TextEncoder();
|
|
98
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
99
|
+
const hashed = wrapper.hash512(tohashBytes);
|
|
100
|
+
const toVerify = "This Is Not The Same";
|
|
101
|
+
const toVerifyBytes: Array<number> = Array.from(encoder.encode(toVerify));
|
|
102
|
+
const verified = wrapper.verify512(hashed, toVerifyBytes);
|
|
103
|
+
assert.equal(false, verified);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("hash threadpool", () => {
|
|
107
|
+
const wrapper = new Blake2Wrapper();
|
|
108
|
+
const tohashed: string = "This is my array to hash";
|
|
109
|
+
const encoder = new TextEncoder();
|
|
110
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
111
|
+
const hashed = wrapper.hash512Threadpool(tohashBytes);
|
|
112
|
+
assert.notEqual(tohashBytes, hashed);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("verify threadpool pass", () => {
|
|
116
|
+
const wrapper = new Blake2Wrapper();
|
|
117
|
+
const tohashed: string = "This is my array to hash";
|
|
118
|
+
const encoder = new TextEncoder();
|
|
119
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
120
|
+
const hashed = wrapper.hash512Threadpool(tohashBytes);
|
|
121
|
+
const toVerifyBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
122
|
+
const verified = wrapper.verify512Threadpool(hashed, toVerifyBytes);
|
|
123
|
+
assert.equal(true, verified);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("verify threadpool fail", () => {
|
|
127
|
+
const wrapper = new Blake2Wrapper();
|
|
128
|
+
const tohashed: string = "This is my array to hash";
|
|
129
|
+
const encoder = new TextEncoder();
|
|
130
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
131
|
+
const hashed = wrapper.hash512Threadpool(tohashBytes);
|
|
132
|
+
const toVerify = "This Is Not The Same";
|
|
133
|
+
const toVerifyBytes: Array<number> = Array.from(encoder.encode(toVerify));
|
|
134
|
+
const verified = wrapper.verify512Threadpool(hashed, toVerifyBytes);
|
|
135
|
+
assert.equal(false, verified);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("Blake2 256", () => {
|
|
40
139
|
it("hash", () => {
|
|
41
|
-
const wrapper = new
|
|
140
|
+
const wrapper = new Blake2Wrapper();
|
|
42
141
|
const tohashed: string = "This is my array to hash";
|
|
43
142
|
const encoder = new TextEncoder();
|
|
44
143
|
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
45
144
|
const hashed = wrapper.hash256(tohashBytes);
|
|
46
145
|
assert.notEqual(tohashBytes, hashed);
|
|
47
146
|
});
|
|
48
|
-
|
|
147
|
+
|
|
49
148
|
it("verify pass", () => {
|
|
50
|
-
const wrapper = new
|
|
149
|
+
const wrapper = new Blake2Wrapper();
|
|
51
150
|
const tohashed: string = "This is my array to hash";
|
|
52
151
|
const encoder = new TextEncoder();
|
|
53
152
|
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
@@ -56,9 +155,9 @@ describe("SHA256 Tests", () => {
|
|
|
56
155
|
const verified = wrapper.verify256(hashed, toVerifyBytes);
|
|
57
156
|
assert.equal(true, verified);
|
|
58
157
|
});
|
|
59
|
-
|
|
158
|
+
|
|
60
159
|
it("verify fail", () => {
|
|
61
|
-
const wrapper = new
|
|
160
|
+
const wrapper = new Blake2Wrapper();
|
|
62
161
|
const tohashed: string = "This is my array to hash";
|
|
63
162
|
const encoder = new TextEncoder();
|
|
64
163
|
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
@@ -68,4 +167,37 @@ describe("SHA256 Tests", () => {
|
|
|
68
167
|
const verified = wrapper.verify256(hashed, toVerifyBytes);
|
|
69
168
|
assert.equal(false, verified);
|
|
70
169
|
});
|
|
71
|
-
|
|
170
|
+
|
|
171
|
+
it("hash threadpool", () => {
|
|
172
|
+
const wrapper = new Blake2Wrapper();
|
|
173
|
+
const tohashed: string = "This is my array to hash";
|
|
174
|
+
const encoder = new TextEncoder();
|
|
175
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
176
|
+
const hashed = wrapper.hash256Threadpool(tohashBytes);
|
|
177
|
+
assert.notEqual(tohashBytes, hashed);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("verify threadpool pass", () => {
|
|
181
|
+
const wrapper = new Blake2Wrapper();
|
|
182
|
+
const tohashed: string = "This is my array to hash";
|
|
183
|
+
const encoder = new TextEncoder();
|
|
184
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
185
|
+
const hashed = wrapper.hash256Threadpool(tohashBytes);
|
|
186
|
+
const toVerifyBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
187
|
+
const verified = wrapper.verify256Threadpool(hashed, toVerifyBytes);
|
|
188
|
+
assert.equal(true, verified);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("verify threadpool fail", () => {
|
|
192
|
+
const wrapper = new Blake2Wrapper();
|
|
193
|
+
const tohashed: string = "This is my array to hash";
|
|
194
|
+
const encoder = new TextEncoder();
|
|
195
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
196
|
+
const hashed = wrapper.hash256Threadpool(tohashBytes);
|
|
197
|
+
const toVerify = "This Is Not The Same";
|
|
198
|
+
const toVerifyBytes: Array<number> = Array.from(encoder.encode(toVerify));
|
|
199
|
+
const verified = wrapper.verify256Threadpool(hashed, toVerifyBytes);
|
|
200
|
+
assert.equal(false, verified);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assert } from "chai";
|
|
2
2
|
import { AESWrapper } from "../src-ts/symmetric/aes-wrapper";
|
|
3
|
+
import { X25519Wrapper } from '../src-ts/key_exchange/x25519';
|
|
3
4
|
import { areEqual } from "./helpers/array";
|
|
4
5
|
|
|
5
6
|
describe("Symmetric Tests", () => {
|
|
@@ -28,4 +29,50 @@ describe("Symmetric Tests", () => {
|
|
|
28
29
|
var result = areEqual(plaintxt, tohashBytes);
|
|
29
30
|
assert.isTrue(result);
|
|
30
31
|
});
|
|
32
|
+
|
|
33
|
+
it("ase 256 X25519 Diffie-Hellman encrypt and decrypt", () => {
|
|
34
|
+
const x25519 = new X25519Wrapper();
|
|
35
|
+
const alice= x25519.generateSecretAndPublicKey();
|
|
36
|
+
const bob = x25519.generateSecretAndPublicKey();
|
|
37
|
+
|
|
38
|
+
const aliceSharedSecret = x25519.generateSharedSecret(alice.secretKey, bob.publicKey);
|
|
39
|
+
const bobSharedSecret = x25519.generateSharedSecret(bob.secretKey, alice.publicKey);
|
|
40
|
+
|
|
41
|
+
const aesWrapper: AESWrapper = new AESWrapper();
|
|
42
|
+
const aliceAesKey = aesWrapper.aes256KeyNonceX25519DiffieHellman(aliceSharedSecret);
|
|
43
|
+
const bobAesKey = aesWrapper.aes256KeyNonceX25519DiffieHellman(bobSharedSecret);
|
|
44
|
+
|
|
45
|
+
const tohashed: string = "This is my array to encrypt";
|
|
46
|
+
const encoder = new TextEncoder();
|
|
47
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
48
|
+
|
|
49
|
+
const aliceCiphertext = aesWrapper.aes256Encrypt(aliceAesKey.aesKey, aliceAesKey.aesNonce, tohashBytes);
|
|
50
|
+
const bobPlaintext = aesWrapper.aes256Decrypt(bobAesKey.aesKey, aliceAesKey.aesNonce, aliceCiphertext);
|
|
51
|
+
|
|
52
|
+
var result = areEqual(bobPlaintext, tohashBytes);
|
|
53
|
+
assert.isTrue(result);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("ase 128 X25519 Diffie-Hellman encrypt and decrypt", () => {
|
|
57
|
+
const x25519 = new X25519Wrapper();
|
|
58
|
+
const alice= x25519.generateSecretAndPublicKey();
|
|
59
|
+
const bob = x25519.generateSecretAndPublicKey();
|
|
60
|
+
|
|
61
|
+
const aliceSharedSecret = x25519.generateSharedSecret(alice.secretKey, bob.publicKey);
|
|
62
|
+
const bobSharedSecret = x25519.generateSharedSecret(bob.secretKey, alice.publicKey);
|
|
63
|
+
|
|
64
|
+
const aesWrapper: AESWrapper = new AESWrapper();
|
|
65
|
+
const aliceAesKey = aesWrapper.aes128KeyNonceX25519DiffieHellman(aliceSharedSecret);
|
|
66
|
+
const bobAesKey = aesWrapper.aes128KeyNonceX25519DiffieHellman(bobSharedSecret);
|
|
67
|
+
|
|
68
|
+
const tohashed: string = "This is my array to encrypt";
|
|
69
|
+
const encoder = new TextEncoder();
|
|
70
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
71
|
+
|
|
72
|
+
const aliceCiphertext = aesWrapper.aes128Encrypt(aliceAesKey.aesKey, aliceAesKey.aesNonce, tohashBytes);
|
|
73
|
+
const bobPlaintext = aesWrapper.aes128Decrypt(bobAesKey.aesKey, aliceAesKey.aesNonce, aliceCiphertext);
|
|
74
|
+
|
|
75
|
+
var result = areEqual(bobPlaintext, tohashBytes);
|
|
76
|
+
assert.isTrue(result);
|
|
77
|
+
});
|
|
31
78
|
});
|