cas-typescript-sdk 1.0.17 → 1.0.19
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 -0
- package/index.d.ts +4 -0
- package/index.node +0 -0
- package/lib/hashers/hasher-base.d.ts +4 -4
- package/lib/hashers/sha-wrapper.d.ts +4 -4
- package/lib/hashers/sha-wrapper.js +4 -4
- package/lib/hybrid/types/aes-rsa-hybrid-initializer.js +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/lib/key_exchange/x25519.d.ts +1 -1
- package/lib/key_exchange/x25519.js +1 -1
- package/lib/password-hashers/argon2-wrapper.d.ts +1 -1
- package/lib/password-hashers/argon2-wrapper.js +1 -1
- package/lib/password-hashers/bcrypt-wrapper.d.ts +1 -1
- package/lib/password-hashers/bcrypt-wrapper.js +1 -1
- package/lib/password-hashers/password-hasher-base.d.ts +1 -1
- package/lib/password-hashers/scrypt-wrapper.d.ts +1 -1
- package/lib/password-hashers/scrypt-wrapper.js +1 -1
- package/lib/sponges/ascon-wrapper.d.ts +6 -0
- package/lib/sponges/ascon-wrapper.js +37 -0
- package/lib/sponges/index.d.ts +2 -0
- package/lib/sponges/index.js +5 -0
- package/lib/symmetric/aes-wrapper.d.ts +3 -3
- package/lib/symmetric/aes-wrapper.js +3 -3
- package/package.json +1 -1
- package/src/lib.rs +5 -0
- package/src/sponges/ascon_aead.rs +84 -0
- package/src/sponges/cas_ascon_aead.rs +6 -0
- package/src-ts/hashers/hasher-base.ts +4 -4
- package/src-ts/hashers/sha-wrapper.ts +4 -4
- package/src-ts/hybrid/types/aes-rsa-hybrid-initializer.ts +1 -1
- package/src-ts/index.ts +6 -4
- package/src-ts/key_exchange/x25519.ts +1 -1
- package/src-ts/password-hashers/argon2-wrapper.ts +1 -1
- package/src-ts/password-hashers/bcrypt-wrapper.ts +1 -1
- package/src-ts/password-hashers/password-hasher-base.ts +1 -1
- package/src-ts/password-hashers/scrypt-wrapper.ts +1 -1
- package/src-ts/sponges/ascon-wrapper.ts +50 -0
- package/src-ts/sponges/index.ts +3 -0
- package/src-ts/symmetric/aes-wrapper.ts +3 -3
- package/test-ts/hasher.test.spec.ts +10 -10
- package/test-ts/insecure-channel.test.spec.ts +8 -8
- package/test-ts/{key-exchange-test.spec.ts → key-exchange.test.spec.ts} +2 -2
- package/test-ts/{password-hasher-test.spec.ts → password-hasher.test.spec.ts} +7 -7
- package/test-ts/sponges.test.spec.ts +28 -0
- package/test-ts/symmetric.test.spec.ts +2 -2
package/Cargo.toml
CHANGED
package/index.d.ts
CHANGED
|
@@ -37,6 +37,10 @@ export function sha512Ed25519DigitalSignature(dataToSign: Array<number>): Shaed2
|
|
|
37
37
|
export function sha512Ed25519DigitalSignatureVerify(publicKey: Array<number>, dataToVerify: Array<number>, signature: Array<number>): boolean
|
|
38
38
|
export function sha256Ed25519DigitalSignature(dataToSign: Array<number>): Shaed25519DalekDigitalSignatureResult
|
|
39
39
|
export function sha256Ed25519DigitalSignatureVerify(publicKey: Array<number>, dataToVerify: Array<number>, signature: Array<number>): boolean
|
|
40
|
+
export function ascon128KeyGenerate(): Array<number>
|
|
41
|
+
export function ascon128NonceGenerate(): Array<number>
|
|
42
|
+
export function ascon128Encrypt(key: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>
|
|
43
|
+
export function ascon128Decrypt(key: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>
|
|
40
44
|
export type x25519SecretPublicKeyResult = X25519SecretPublicKeyResult
|
|
41
45
|
export class X25519SecretPublicKeyResult {
|
|
42
46
|
publicKey: Array<number>
|
package/index.node
CHANGED
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export interface IHasherBase {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
hash512(dataToHash: number[]): number[];
|
|
3
|
+
verify512(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
4
|
+
hash256(dataToHash: number[]): number[];
|
|
5
|
+
verify256(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
6
6
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IHasherBase } from "./hasher-base";
|
|
2
2
|
export declare class SHAWrapper implements IHasherBase {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
hash512(dataToHash: number[]): number[];
|
|
4
|
+
verify512(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
5
|
+
hash256(dataToHash: number[]): number[];
|
|
6
|
+
verify256(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
7
7
|
}
|
|
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SHAWrapper = void 0;
|
|
4
4
|
const index_1 = require("../../index");
|
|
5
5
|
class SHAWrapper {
|
|
6
|
-
|
|
6
|
+
hash512(dataToHash) {
|
|
7
7
|
if (!dataToHash || dataToHash.length === 0) {
|
|
8
8
|
throw new Error("You must provide an allocated array of data");
|
|
9
9
|
}
|
|
10
10
|
return (0, index_1.sha512)(dataToHash);
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
verify512(dataToHash, dataToVerify) {
|
|
13
13
|
if (!dataToHash || dataToHash.length === 0) {
|
|
14
14
|
throw new Error("You must provide an allocated array of data");
|
|
15
15
|
}
|
|
@@ -18,13 +18,13 @@ class SHAWrapper {
|
|
|
18
18
|
}
|
|
19
19
|
return (0, index_1.sha512Verify)(dataToHash, dataToVerify);
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
hash256(dataToHash) {
|
|
22
22
|
if (!dataToHash || dataToHash.length === 0) {
|
|
23
23
|
throw new Error("You must provide an allocated array of data");
|
|
24
24
|
}
|
|
25
25
|
return (0, index_1.sha256)(dataToHash);
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
verify256(dataToHash, dataToVerify) {
|
|
28
28
|
if (!dataToHash || dataToHash.length === 0) {
|
|
29
29
|
throw new Error("You must provide an allocated array of data");
|
|
30
30
|
}
|
|
@@ -15,7 +15,7 @@ class AESRSAHybridInitializer {
|
|
|
15
15
|
this.aesType = aesType;
|
|
16
16
|
let aesWrapper = new symmetric_1.AESWrapper();
|
|
17
17
|
this.aesKey = (aesType === 128) ? aesWrapper.aes128Key() : aesWrapper.aes256Key();
|
|
18
|
-
this.aesNonce = aesWrapper.
|
|
18
|
+
this.aesNonce = aesWrapper.generateAESNonce();
|
|
19
19
|
if (rsaSize !== 1028 && rsaSize !== 2048 && rsaSize !== 4096) {
|
|
20
20
|
throw new Error("You must provide an appropriate RSA Key pair size to generate a hybrid initalizer");
|
|
21
21
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -5,4 +5,5 @@ import { AESWrapper } from "./symmetric/index";
|
|
|
5
5
|
import { RsaKeyPairResult, RSAWrapper } from "./asymmetric/index";
|
|
6
6
|
import { AesRsaHybridEncryptResult, AESRSAHybridInitializer, HybridEncryptionWrapper } from "./hybrid/index";
|
|
7
7
|
import { DigitalSignatureFactory, DigitalSignatureSHA256Wrapper, DigitalSignatureSHA512Wrapper, DigitalSignatureType } from "./digital-signature";
|
|
8
|
-
|
|
8
|
+
import { AsconWrapper } from "./sponges/index";
|
|
9
|
+
export { AesRsaHybridEncryptResult, AESRSAHybridInitializer, AESWrapper, Argon2Wrapper, AsconWrapper, BCryptWrapper, DigitalSignatureFactory, DigitalSignatureSHA256Wrapper, DigitalSignatureSHA512Wrapper, DigitalSignatureType, HasherFactory, HasherType, HybridEncryptionWrapper, PasswordHasherFactory, PasswordHasherType, RsaKeyPairResult, RSAWrapper, ScryptWrapper, SHAWrapper, X25519Wrapper, };
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.X25519Wrapper = exports.SHAWrapper = exports.ScryptWrapper = exports.RSAWrapper = exports.RsaKeyPairResult = exports.PasswordHasherType = exports.PasswordHasherFactory = exports.HybridEncryptionWrapper = exports.HasherType = exports.HasherFactory = exports.DigitalSignatureType = exports.DigitalSignatureSHA512Wrapper = exports.DigitalSignatureSHA256Wrapper = exports.DigitalSignatureFactory = exports.BCryptWrapper = exports.AsconWrapper = exports.Argon2Wrapper = exports.AESWrapper = exports.AESRSAHybridInitializer = exports.AesRsaHybridEncryptResult = void 0;
|
|
4
4
|
const index_1 = require("./password-hashers/index");
|
|
5
5
|
Object.defineProperty(exports, "Argon2Wrapper", { enumerable: true, get: function () { return index_1.Argon2Wrapper; } });
|
|
6
6
|
Object.defineProperty(exports, "BCryptWrapper", { enumerable: true, get: function () { return index_1.BCryptWrapper; } });
|
|
@@ -27,3 +27,5 @@ Object.defineProperty(exports, "DigitalSignatureFactory", { enumerable: true, ge
|
|
|
27
27
|
Object.defineProperty(exports, "DigitalSignatureSHA256Wrapper", { enumerable: true, get: function () { return digital_signature_1.DigitalSignatureSHA256Wrapper; } });
|
|
28
28
|
Object.defineProperty(exports, "DigitalSignatureSHA512Wrapper", { enumerable: true, get: function () { return digital_signature_1.DigitalSignatureSHA512Wrapper; } });
|
|
29
29
|
Object.defineProperty(exports, "DigitalSignatureType", { enumerable: true, get: function () { return digital_signature_1.DigitalSignatureType; } });
|
|
30
|
+
const index_7 = require("./sponges/index");
|
|
31
|
+
Object.defineProperty(exports, "AsconWrapper", { enumerable: true, get: function () { return index_7.AsconWrapper; } });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { X25519SecretPublicKeyResult } from "../../index";
|
|
2
2
|
export declare class X25519Wrapper {
|
|
3
3
|
generateSecretAndPublicKey(): X25519SecretPublicKeyResult;
|
|
4
|
-
|
|
4
|
+
generateSharedSecret(secretKey: Array<number>, publicKey: Array<number>): number[];
|
|
5
5
|
}
|
|
@@ -6,7 +6,7 @@ class X25519Wrapper {
|
|
|
6
6
|
generateSecretAndPublicKey() {
|
|
7
7
|
return (0, index_1.x25519GenerateSecretAndPublicKey)();
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
generateSharedSecret(secretKey, publicKey) {
|
|
10
10
|
return (0, index_1.x25519DiffieHellman)(secretKey, publicKey);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
2
2
|
export declare class Argon2Wrapper implements IPasswordHasherBase {
|
|
3
3
|
hashPassword(password: string): string;
|
|
4
|
-
|
|
4
|
+
verify(hashedPassword: string, passwordToVerify: string): boolean;
|
|
5
5
|
}
|
|
@@ -9,7 +9,7 @@ class Argon2Wrapper {
|
|
|
9
9
|
}
|
|
10
10
|
return (0, index_1.argon2Hash)(password);
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
verify(hashedPassword, passwordToVerify) {
|
|
13
13
|
if (!hashedPassword || !passwordToVerify) {
|
|
14
14
|
throw new Error("You must provide a hashed password and a plaintext password to verify with Argon2");
|
|
15
15
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
2
2
|
export declare class BCryptWrapper implements IPasswordHasherBase {
|
|
3
3
|
hashPassword(password: string): string;
|
|
4
|
-
|
|
4
|
+
verify(hashedPassword: string, passwordToVerify: string): boolean;
|
|
5
5
|
}
|
|
@@ -9,7 +9,7 @@ class BCryptWrapper {
|
|
|
9
9
|
}
|
|
10
10
|
return (0, index_1.bcryptHash)(password);
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
verify(hashedPassword, passwordToVerify) {
|
|
13
13
|
if (!hashedPassword || !passwordToVerify) {
|
|
14
14
|
throw new Error("You must provide a hashed password and a plaintext password to verify with Argon2");
|
|
15
15
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IPasswordHasherBase } from "./password-hasher-base";
|
|
2
2
|
export declare class ScryptWrapper implements IPasswordHasherBase {
|
|
3
3
|
hashPassword(password: string): string;
|
|
4
|
-
|
|
4
|
+
verify(hashedPassword: string, passwordToVerify: string): boolean;
|
|
5
5
|
}
|
|
@@ -9,7 +9,7 @@ class ScryptWrapper {
|
|
|
9
9
|
}
|
|
10
10
|
return (0, index_1.scryptHash)(password);
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
verify(hashedPassword, passwordToVerify) {
|
|
13
13
|
if (!hashedPassword || !passwordToVerify) {
|
|
14
14
|
throw new Error("You must provide a hashed password and a plaintext password to verify with Scrypt");
|
|
15
15
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare class AsconWrapper {
|
|
2
|
+
ascon128Key(): Array<number>;
|
|
3
|
+
ascon128Nonce(): Array<number>;
|
|
4
|
+
ascon128Encrypt(key: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>;
|
|
5
|
+
ascon128Decrypt(key: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AsconWrapper = void 0;
|
|
4
|
+
const index_1 = require("../../index");
|
|
5
|
+
class AsconWrapper {
|
|
6
|
+
ascon128Key() {
|
|
7
|
+
return (0, index_1.ascon128KeyGenerate)();
|
|
8
|
+
}
|
|
9
|
+
ascon128Nonce() {
|
|
10
|
+
return (0, index_1.ascon128NonceGenerate)();
|
|
11
|
+
}
|
|
12
|
+
ascon128Encrypt(key, nonce, plaintext) {
|
|
13
|
+
if (!key || key.length === 0) {
|
|
14
|
+
throw new Error("Key is required");
|
|
15
|
+
}
|
|
16
|
+
if (!nonce || nonce.length === 0) {
|
|
17
|
+
throw new Error("Nonce is required");
|
|
18
|
+
}
|
|
19
|
+
if (!plaintext || plaintext.length === 0) {
|
|
20
|
+
throw new Error("Plaintext is required");
|
|
21
|
+
}
|
|
22
|
+
return (0, index_1.ascon128Encrypt)(key, nonce, plaintext);
|
|
23
|
+
}
|
|
24
|
+
ascon128Decrypt(key, nonce, ciphertext) {
|
|
25
|
+
if (!key || key.length === 0) {
|
|
26
|
+
throw new Error("Key is required");
|
|
27
|
+
}
|
|
28
|
+
if (!nonce || nonce.length === 0) {
|
|
29
|
+
throw new Error("Nonce is required");
|
|
30
|
+
}
|
|
31
|
+
if (!ciphertext || ciphertext.length === 0) {
|
|
32
|
+
throw new Error("Ciphertext is required");
|
|
33
|
+
}
|
|
34
|
+
return (0, index_1.ascon128Decrypt)(key, nonce, ciphertext);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.AsconWrapper = AsconWrapper;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AsconWrapper = void 0;
|
|
4
|
+
const ascon_wrapper_1 = require("./ascon-wrapper");
|
|
5
|
+
Object.defineProperty(exports, "AsconWrapper", { enumerable: true, get: function () { return ascon_wrapper_1.AsconWrapper; } });
|
|
@@ -2,11 +2,11 @@ import { AesKeyFromX25519SharedSecret } from "../../index";
|
|
|
2
2
|
export declare class AESWrapper {
|
|
3
3
|
aes128Key(): Array<number>;
|
|
4
4
|
aes256Key(): Array<number>;
|
|
5
|
-
|
|
5
|
+
generateAESNonce(): Array<number>;
|
|
6
6
|
aes128Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>;
|
|
7
7
|
aes128Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>;
|
|
8
8
|
aes256Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>;
|
|
9
9
|
aes256Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
aes256KeyNonceX25519DiffieHellman(shared_secret: Array<number>): AesKeyFromX25519SharedSecret;
|
|
11
|
+
aes128KeyNonceX25519DiffieHellman(shared_secret: Array<number>): AesKeyFromX25519SharedSecret;
|
|
12
12
|
}
|
|
@@ -9,7 +9,7 @@ class AESWrapper {
|
|
|
9
9
|
aes256Key() {
|
|
10
10
|
return (0, index_1.aes256Key)();
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
generateAESNonce() {
|
|
13
13
|
return (0, index_1.aesNonce)();
|
|
14
14
|
}
|
|
15
15
|
aes128Encrypt(aesKey, nonce, plaintext) {
|
|
@@ -24,10 +24,10 @@ class AESWrapper {
|
|
|
24
24
|
aes256Decrypt(aesKey, nonce, ciphertext) {
|
|
25
25
|
return (0, index_1.aes256Decrypt)(aesKey, nonce, ciphertext);
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
aes256KeyNonceX25519DiffieHellman(shared_secret) {
|
|
28
28
|
return (0, index_1.aes256KeyFromX25519SharedSecret)(shared_secret);
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
aes128KeyNonceX25519DiffieHellman(shared_secret) {
|
|
31
31
|
return (0, index_1.aes128KeyFromX25519SharedSecret)(shared_secret);
|
|
32
32
|
}
|
|
33
33
|
}
|
package/package.json
CHANGED
package/src/lib.rs
CHANGED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
|
|
2
|
+
use aes_gcm::AeadCore;
|
|
3
|
+
use ascon_aead::{aead::{generic_array::GenericArray, Aead, KeyInit, OsRng}, Ascon128};
|
|
4
|
+
use napi_derive::napi;
|
|
5
|
+
|
|
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
|
+
#[napi]
|
|
36
|
+
pub fn ascon128_key_generate() -> Vec<u8> {
|
|
37
|
+
return AsconAead::generate_key();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
#[test]
|
|
41
|
+
fn test_ascon128_key_generate() {
|
|
42
|
+
let key = ascon128_key_generate();
|
|
43
|
+
assert_eq!(key.len(), 16);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
#[napi]
|
|
47
|
+
pub fn ascon128_nonce_generate() -> Vec<u8> {
|
|
48
|
+
return AsconAead::generate_nonce();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
#[test]
|
|
52
|
+
pub fn test_ascon128_nonce_generate() {
|
|
53
|
+
let nonce = ascon128_nonce_generate();
|
|
54
|
+
assert_eq!(nonce.len(), 16);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
#[napi]
|
|
58
|
+
pub fn ascon128_encrypt(key: Vec<u8>, nonce: Vec<u8>, plaintext: Vec<u8>) -> Vec<u8> {
|
|
59
|
+
return AsconAead::encrypt(key, nonce, plaintext);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#[test]
|
|
63
|
+
pub fn test_ascon128_encrypt() {
|
|
64
|
+
let key = AsconAead::generate_key();
|
|
65
|
+
let nonce = AsconAead::generate_nonce();
|
|
66
|
+
let plaintext = b"Hello, World!".to_vec();
|
|
67
|
+
let ciphertext = ascon128_encrypt(key.clone(), nonce.clone(), plaintext.clone());
|
|
68
|
+
assert_ne!(ciphertext, plaintext);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
#[napi]
|
|
72
|
+
pub fn ascon128_decrypt(key: Vec<u8>, nonce: Vec<u8>, ciphertext: Vec<u8>) -> Vec<u8> {
|
|
73
|
+
return AsconAead::decrypt(key, nonce, ciphertext);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
#[test]
|
|
77
|
+
pub fn test_ascon128_decrypt() {
|
|
78
|
+
let key = AsconAead::generate_key();
|
|
79
|
+
let nonce = AsconAead::generate_nonce();
|
|
80
|
+
let plaintext = b"Hello, World!".to_vec();
|
|
81
|
+
let ciphertext = ascon128_encrypt(key.clone(), nonce.clone(), plaintext.clone());
|
|
82
|
+
let decrypted = ascon128_decrypt(key.clone(), nonce.clone(), ciphertext.clone());
|
|
83
|
+
assert_eq!(decrypted, plaintext);
|
|
84
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export interface IHasherBase {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
hash512(dataToHash: number[]): number[];
|
|
3
|
+
verify512(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
4
|
+
hash256(dataToHash: number[]): number[];
|
|
5
|
+
verify256(dataToHash: number[], dataToVerify: number[]): boolean;
|
|
6
6
|
}
|
|
@@ -2,14 +2,14 @@ import { sha256, sha256Verify, sha512, sha512Verify } from "../../index";
|
|
|
2
2
|
import { IHasherBase } from "./hasher-base";
|
|
3
3
|
|
|
4
4
|
export class SHAWrapper implements IHasherBase {
|
|
5
|
-
|
|
5
|
+
hash512(dataToHash: number[]): number[] {
|
|
6
6
|
if (!dataToHash || dataToHash.length === 0) {
|
|
7
7
|
throw new Error("You must provide an allocated array of data");
|
|
8
8
|
}
|
|
9
9
|
return sha512(dataToHash);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
verify512(dataToHash: number[], dataToVerify: number[]): boolean {
|
|
13
13
|
if (!dataToHash || dataToHash.length === 0) {
|
|
14
14
|
throw new Error("You must provide an allocated array of data");
|
|
15
15
|
}
|
|
@@ -19,14 +19,14 @@ export class SHAWrapper implements IHasherBase {
|
|
|
19
19
|
return sha512Verify(dataToHash, dataToVerify);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
hash256(dataToHash: number[]): number[] {
|
|
23
23
|
if (!dataToHash || dataToHash.length === 0) {
|
|
24
24
|
throw new Error("You must provide an allocated array of data");
|
|
25
25
|
}
|
|
26
26
|
return sha256(dataToHash);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
verify256(dataToHash: number[], dataToVerify: number[]): boolean {
|
|
30
30
|
if (!dataToHash || dataToHash.length === 0) {
|
|
31
31
|
throw new Error("You must provide an allocated array of data");
|
|
32
32
|
}
|
|
@@ -15,7 +15,7 @@ export class AESRSAHybridInitializer {
|
|
|
15
15
|
this.aesType = aesType;
|
|
16
16
|
let aesWrapper = new AESWrapper();
|
|
17
17
|
this.aesKey = (aesType === 128) ? aesWrapper.aes128Key() : aesWrapper.aes256Key();
|
|
18
|
-
this.aesNonce = aesWrapper.
|
|
18
|
+
this.aesNonce = aesWrapper.generateAESNonce();
|
|
19
19
|
if (rsaSize !== 1028 && rsaSize !== 2048 && rsaSize !== 4096) {
|
|
20
20
|
throw new Error("You must provide an appropriate RSA Key pair size to generate a hybrid initalizer");
|
|
21
21
|
}
|
package/src-ts/index.ts
CHANGED
|
@@ -20,13 +20,19 @@ import {
|
|
|
20
20
|
DigitalSignatureSHA512Wrapper,
|
|
21
21
|
DigitalSignatureType,
|
|
22
22
|
} from "./digital-signature";
|
|
23
|
+
import { AsconWrapper } from "./sponges/index";
|
|
23
24
|
|
|
24
25
|
export {
|
|
25
26
|
AesRsaHybridEncryptResult,
|
|
26
27
|
AESRSAHybridInitializer,
|
|
27
28
|
AESWrapper,
|
|
28
29
|
Argon2Wrapper,
|
|
30
|
+
AsconWrapper,
|
|
29
31
|
BCryptWrapper,
|
|
32
|
+
DigitalSignatureFactory,
|
|
33
|
+
DigitalSignatureSHA256Wrapper,
|
|
34
|
+
DigitalSignatureSHA512Wrapper,
|
|
35
|
+
DigitalSignatureType,
|
|
30
36
|
HasherFactory,
|
|
31
37
|
HasherType,
|
|
32
38
|
HybridEncryptionWrapper,
|
|
@@ -37,8 +43,4 @@ export {
|
|
|
37
43
|
ScryptWrapper,
|
|
38
44
|
SHAWrapper,
|
|
39
45
|
X25519Wrapper,
|
|
40
|
-
DigitalSignatureFactory,
|
|
41
|
-
DigitalSignatureSHA256Wrapper,
|
|
42
|
-
DigitalSignatureSHA512Wrapper,
|
|
43
|
-
DigitalSignatureType,
|
|
44
46
|
};
|
|
@@ -5,7 +5,7 @@ export class X25519Wrapper {
|
|
|
5
5
|
return x25519GenerateSecretAndPublicKey();
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
public
|
|
8
|
+
public generateSharedSecret(secretKey: Array<number>, publicKey: Array<number>) {
|
|
9
9
|
return x25519DiffieHellman(secretKey, publicKey);
|
|
10
10
|
}
|
|
11
11
|
}
|
|
@@ -9,7 +9,7 @@ export class Argon2Wrapper implements IPasswordHasherBase {
|
|
|
9
9
|
return argon2Hash(password);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
public
|
|
12
|
+
public verify(hashedPassword: string, passwordToVerify: string): boolean {
|
|
13
13
|
if (!hashedPassword || !passwordToVerify) {
|
|
14
14
|
throw new Error("You must provide a hashed password and a plaintext password to verify with Argon2");
|
|
15
15
|
}
|
|
@@ -10,7 +10,7 @@ export class ScryptWrapper implements IPasswordHasherBase {
|
|
|
10
10
|
return scryptHash(password);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
public
|
|
13
|
+
public verify(hashedPassword: string, passwordToVerify: string): boolean {
|
|
14
14
|
if (!hashedPassword || !passwordToVerify) {
|
|
15
15
|
throw new Error("You must provide a hashed password and a plaintext password to verify with Scrypt");
|
|
16
16
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ascon128Decrypt,
|
|
3
|
+
ascon128Encrypt,
|
|
4
|
+
ascon128KeyGenerate,
|
|
5
|
+
ascon128NonceGenerate,
|
|
6
|
+
} from "../../index";
|
|
7
|
+
|
|
8
|
+
export class AsconWrapper {
|
|
9
|
+
ascon128Key(): Array<number> {
|
|
10
|
+
return ascon128KeyGenerate();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
ascon128Nonce(): Array<number> {
|
|
14
|
+
return ascon128NonceGenerate();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
ascon128Encrypt(
|
|
18
|
+
key: Array<number>,
|
|
19
|
+
nonce: Array<number>,
|
|
20
|
+
plaintext: Array<number>,
|
|
21
|
+
): Array<number> {
|
|
22
|
+
if (!key || key.length === 0) {
|
|
23
|
+
throw new Error("Key is required");
|
|
24
|
+
}
|
|
25
|
+
if (!nonce || nonce.length === 0) {
|
|
26
|
+
throw new Error("Nonce is required");
|
|
27
|
+
}
|
|
28
|
+
if (!plaintext || plaintext.length === 0) {
|
|
29
|
+
throw new Error("Plaintext is required");
|
|
30
|
+
}
|
|
31
|
+
return ascon128Encrypt(key, nonce, plaintext);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
ascon128Decrypt(
|
|
35
|
+
key: Array<number>,
|
|
36
|
+
nonce: Array<number>,
|
|
37
|
+
ciphertext: Array<number>,
|
|
38
|
+
): Array<number> {
|
|
39
|
+
if (!key || key.length === 0) {
|
|
40
|
+
throw new Error("Key is required");
|
|
41
|
+
}
|
|
42
|
+
if (!nonce || nonce.length === 0) {
|
|
43
|
+
throw new Error("Nonce is required");
|
|
44
|
+
}
|
|
45
|
+
if (!ciphertext || ciphertext.length === 0) {
|
|
46
|
+
throw new Error("Ciphertext is required");
|
|
47
|
+
}
|
|
48
|
+
return ascon128Decrypt(key, nonce, ciphertext);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -20,7 +20,7 @@ export class AESWrapper {
|
|
|
20
20
|
return aes256Key();
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
public
|
|
23
|
+
public generateAESNonce(): Array<number> {
|
|
24
24
|
return aesNonce();
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -40,11 +40,11 @@ export class AESWrapper {
|
|
|
40
40
|
return aes256Decrypt(aesKey, nonce, ciphertext);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
public
|
|
43
|
+
public aes256KeyNonceX25519DiffieHellman(shared_secret: Array<number>): AesKeyFromX25519SharedSecret {
|
|
44
44
|
return aes256KeyFromX25519SharedSecret(shared_secret);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
public
|
|
47
|
+
public aes128KeyNonceX25519DiffieHellman(shared_secret: Array<number>): AesKeyFromX25519SharedSecret {
|
|
48
48
|
return aes128KeyFromX25519SharedSecret(shared_secret);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
@@ -7,7 +7,7 @@ describe("SHA512 Tests", () => {
|
|
|
7
7
|
const tohashed: string = "This is my array to hash";
|
|
8
8
|
const encoder = new TextEncoder();
|
|
9
9
|
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
10
|
-
const hashed = wrapper.
|
|
10
|
+
const hashed = wrapper.hash512(tohashBytes);
|
|
11
11
|
assert.notEqual(tohashBytes, hashed);
|
|
12
12
|
});
|
|
13
13
|
|
|
@@ -16,9 +16,9 @@ describe("SHA512 Tests", () => {
|
|
|
16
16
|
const tohashed: string = "This is my array to hash";
|
|
17
17
|
const encoder = new TextEncoder();
|
|
18
18
|
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
19
|
-
const hashed = wrapper.
|
|
19
|
+
const hashed = wrapper.hash512(tohashBytes);
|
|
20
20
|
const toVerifyBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
21
|
-
const verified = wrapper.
|
|
21
|
+
const verified = wrapper.verify512(hashed, toVerifyBytes);
|
|
22
22
|
assert.equal(true, verified);
|
|
23
23
|
});
|
|
24
24
|
|
|
@@ -27,10 +27,10 @@ describe("SHA512 Tests", () => {
|
|
|
27
27
|
const tohashed: string = "This is my array to hash";
|
|
28
28
|
const encoder = new TextEncoder();
|
|
29
29
|
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
30
|
-
const hashed = wrapper.
|
|
30
|
+
const hashed = wrapper.hash512(tohashBytes);
|
|
31
31
|
const toVerify = "This Is Not The Same";
|
|
32
32
|
const toVerifyBytes: Array<number> = Array.from(encoder.encode(toVerify));
|
|
33
|
-
const verified = wrapper.
|
|
33
|
+
const verified = wrapper.verify512(hashed, toVerifyBytes);
|
|
34
34
|
assert.equal(false, verified);
|
|
35
35
|
});
|
|
36
36
|
});
|
|
@@ -42,7 +42,7 @@ describe("SHA256 Tests", () => {
|
|
|
42
42
|
const tohashed: string = "This is my array to hash";
|
|
43
43
|
const encoder = new TextEncoder();
|
|
44
44
|
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
45
|
-
const hashed = wrapper.
|
|
45
|
+
const hashed = wrapper.hash256(tohashBytes);
|
|
46
46
|
assert.notEqual(tohashBytes, hashed);
|
|
47
47
|
});
|
|
48
48
|
|
|
@@ -51,9 +51,9 @@ describe("SHA256 Tests", () => {
|
|
|
51
51
|
const tohashed: string = "This is my array to hash";
|
|
52
52
|
const encoder = new TextEncoder();
|
|
53
53
|
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
54
|
-
const hashed = wrapper.
|
|
54
|
+
const hashed = wrapper.hash256(tohashBytes);
|
|
55
55
|
const toVerifyBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
56
|
-
const verified = wrapper.
|
|
56
|
+
const verified = wrapper.verify256(hashed, toVerifyBytes);
|
|
57
57
|
assert.equal(true, verified);
|
|
58
58
|
});
|
|
59
59
|
|
|
@@ -62,10 +62,10 @@ describe("SHA256 Tests", () => {
|
|
|
62
62
|
const tohashed: string = "This is my array to hash";
|
|
63
63
|
const encoder = new TextEncoder();
|
|
64
64
|
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
65
|
-
const hashed = wrapper.
|
|
65
|
+
const hashed = wrapper.hash256(tohashBytes);
|
|
66
66
|
const toVerify = "This Is Not The Same";
|
|
67
67
|
const toVerifyBytes: Array<number> = Array.from(encoder.encode(toVerify));
|
|
68
|
-
const verified = wrapper.
|
|
68
|
+
const verified = wrapper.verify256(hashed, toVerifyBytes);
|
|
69
69
|
assert.equal(false, verified);
|
|
70
70
|
});
|
|
71
71
|
});
|
|
@@ -11,11 +11,11 @@ describe("Insecure Channel Tests", () => {
|
|
|
11
11
|
const alice_keys: X25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
|
|
12
12
|
const bob_keys: X25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
|
|
13
13
|
|
|
14
|
-
const alice_shared_secret = x25519Wrapper.
|
|
15
|
-
const bob_shared_secret = x25519Wrapper.
|
|
14
|
+
const alice_shared_secret = x25519Wrapper.generateSharedSecret(alice_keys.secretKey, bob_keys.publicKey);
|
|
15
|
+
const bob_shared_secret = x25519Wrapper.generateSharedSecret(bob_keys.secretKey, alice_keys.publicKey);
|
|
16
16
|
|
|
17
|
-
const alice_aes_key = aesWrapper.
|
|
18
|
-
const bob_aes_key = aesWrapper.
|
|
17
|
+
const alice_aes_key = aesWrapper.aes256KeyNonceX25519DiffieHellman(alice_shared_secret);
|
|
18
|
+
const bob_aes_key = aesWrapper.aes256KeyNonceX25519DiffieHellman(bob_shared_secret);
|
|
19
19
|
|
|
20
20
|
const tohashed: string = "This is my encrypt text";
|
|
21
21
|
const encoder = new TextEncoder();
|
|
@@ -33,11 +33,11 @@ describe("Insecure Channel Tests", () => {
|
|
|
33
33
|
const alice_keys: X25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
|
|
34
34
|
const bob_keys: X25519SecretPublicKeyResult = x25519Wrapper.generateSecretAndPublicKey();
|
|
35
35
|
|
|
36
|
-
const alice_shared_secret = x25519Wrapper.
|
|
37
|
-
const bob_shared_secret = x25519Wrapper.
|
|
36
|
+
const alice_shared_secret = x25519Wrapper.generateSharedSecret(alice_keys.secretKey, bob_keys.publicKey);
|
|
37
|
+
const bob_shared_secret = x25519Wrapper.generateSharedSecret(bob_keys.secretKey, alice_keys.publicKey);
|
|
38
38
|
|
|
39
|
-
const alice_aes_key = aesWrapper.
|
|
40
|
-
const bob_aes_key = aesWrapper.
|
|
39
|
+
const alice_aes_key = aesWrapper.aes128KeyNonceX25519DiffieHellman(alice_shared_secret);
|
|
40
|
+
const bob_aes_key = aesWrapper.aes128KeyNonceX25519DiffieHellman(bob_shared_secret);
|
|
41
41
|
|
|
42
42
|
const tohashed: string = "This is my encrypt text";
|
|
43
43
|
const encoder = new TextEncoder();
|
|
@@ -8,11 +8,11 @@ describe("X25519 Key Exchange", () => {
|
|
|
8
8
|
const alice = wrapper.generateSecretAndPublicKey();
|
|
9
9
|
const bob = wrapper.generateSecretAndPublicKey();
|
|
10
10
|
|
|
11
|
-
const alice_shared_secret = wrapper.
|
|
11
|
+
const alice_shared_secret = wrapper.generateSharedSecret(
|
|
12
12
|
alice.secretKey,
|
|
13
13
|
bob.publicKey,
|
|
14
14
|
);
|
|
15
|
-
const bob_shared_secret = wrapper.
|
|
15
|
+
const bob_shared_secret = wrapper.generateSharedSecret(
|
|
16
16
|
bob.secretKey,
|
|
17
17
|
alice.publicKey,
|
|
18
18
|
);
|
|
@@ -4,7 +4,7 @@ import { ScryptWrapper } from "../src-ts/password-hashers/index";
|
|
|
4
4
|
import {
|
|
5
5
|
PasswordHasherFactory,
|
|
6
6
|
PasswordHasherType,
|
|
7
|
-
} from "../src-ts/password-hashers
|
|
7
|
+
} from "../src-ts/password-hashers";
|
|
8
8
|
|
|
9
9
|
describe("Bcrypt Tests", () => {
|
|
10
10
|
it("hash", () => {
|
|
@@ -18,7 +18,7 @@ describe("Bcrypt Tests", () => {
|
|
|
18
18
|
const hasher: BCryptWrapper = new BCryptWrapper();
|
|
19
19
|
const password: string = "NotThisPassword!@";
|
|
20
20
|
const hashedPassword: string = hasher.hashPassword(password);
|
|
21
|
-
const isValid: boolean = hasher.
|
|
21
|
+
const isValid: boolean = hasher.verify(hashedPassword, password);
|
|
22
22
|
expect(isValid).to.equal(true);
|
|
23
23
|
});
|
|
24
24
|
|
|
@@ -26,7 +26,7 @@ describe("Bcrypt Tests", () => {
|
|
|
26
26
|
const hasher: BCryptWrapper = new BCryptWrapper();
|
|
27
27
|
const password: string = "NotThisPassword!@";
|
|
28
28
|
const hashedPassword: string = hasher.hashPassword(password);
|
|
29
|
-
const isValid: boolean = hasher.
|
|
29
|
+
const isValid: boolean = hasher.verify(
|
|
30
30
|
hashedPassword,
|
|
31
31
|
"ThesePasswordsDoNotMatch",
|
|
32
32
|
);
|
|
@@ -50,7 +50,7 @@ describe("Scrypt Tests", () => {
|
|
|
50
50
|
);
|
|
51
51
|
const password: string = "ScryptRocks1231231";
|
|
52
52
|
const hashed: string = hasher.hashPassword(password);
|
|
53
|
-
const verified: boolean = hasher.
|
|
53
|
+
const verified: boolean = hasher.verify(hashed, password);
|
|
54
54
|
assert.isTrue(verified);
|
|
55
55
|
});
|
|
56
56
|
|
|
@@ -60,7 +60,7 @@ describe("Scrypt Tests", () => {
|
|
|
60
60
|
);
|
|
61
61
|
const password: string = "ScryptRocksSomeGarbageText";
|
|
62
62
|
const hashed: string = hasher.hashPassword(password);
|
|
63
|
-
const verified: boolean = hasher.
|
|
63
|
+
const verified: boolean = hasher.verify(
|
|
64
64
|
hashed,
|
|
65
65
|
"make this fail, its not the same",
|
|
66
66
|
);
|
|
@@ -84,7 +84,7 @@ describe("Argon2 Tests", () => {
|
|
|
84
84
|
);
|
|
85
85
|
const password: string = "ScryptRocks1231231";
|
|
86
86
|
const hashed: string = hasher.hashPassword(password);
|
|
87
|
-
const verified: boolean = hasher.
|
|
87
|
+
const verified: boolean = hasher.verify(hashed, password);
|
|
88
88
|
assert.isTrue(verified);
|
|
89
89
|
});
|
|
90
90
|
|
|
@@ -94,7 +94,7 @@ describe("Argon2 Tests", () => {
|
|
|
94
94
|
);
|
|
95
95
|
const password: string = "ScryptRocksSomeGarbageText";
|
|
96
96
|
const hashed: string = hasher.hashPassword(password);
|
|
97
|
-
const verified: boolean = hasher.
|
|
97
|
+
const verified: boolean = hasher.verify(
|
|
98
98
|
hashed,
|
|
99
99
|
"make this fail, its not the same",
|
|
100
100
|
);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AsconWrapper } from "../src-ts/sponges/ascon-wrapper";
|
|
2
|
+
import { assert } from "chai";
|
|
3
|
+
import { areEqual } from "./helpers/array";
|
|
4
|
+
|
|
5
|
+
describe("Sponges Tests", () => {
|
|
6
|
+
it("Ascon 128 Encrypt", () => {
|
|
7
|
+
const wrapper: AsconWrapper = new AsconWrapper();
|
|
8
|
+
const key: Array<number> = wrapper.ascon128Key();
|
|
9
|
+
const nonce: Array<number> = wrapper.ascon128Nonce();
|
|
10
|
+
const tohashed: string = "This is my array to encrypt";
|
|
11
|
+
const encoder = new TextEncoder();
|
|
12
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
13
|
+
const ciphertext = wrapper.ascon128Encrypt(key, nonce, tohashBytes);
|
|
14
|
+
assert.isNotTrue(areEqual(tohashBytes, ciphertext));
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it ("Ascon 128 Decrypt", () => {
|
|
18
|
+
const wrapper: AsconWrapper = new AsconWrapper();
|
|
19
|
+
const key: Array<number> = wrapper.ascon128Key();
|
|
20
|
+
const nonce: Array<number> = wrapper.ascon128Nonce();
|
|
21
|
+
const tohashed: string = "This is my array to encrypt";
|
|
22
|
+
const encoder = new TextEncoder();
|
|
23
|
+
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
24
|
+
const ciphertext = wrapper.ascon128Encrypt(key, nonce, tohashBytes);
|
|
25
|
+
const plaintext = wrapper.ascon128Decrypt(key, nonce, ciphertext);
|
|
26
|
+
assert.equal(areEqual(plaintext, tohashBytes), true);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -6,7 +6,7 @@ describe("Symmetric Tests", () => {
|
|
|
6
6
|
it("aes 128 encrypt and decrypt equals", () => {
|
|
7
7
|
const aesWrapper: AESWrapper = new AESWrapper();
|
|
8
8
|
const aesKey = aesWrapper.aes128Key();
|
|
9
|
-
const aesNonce = aesWrapper.
|
|
9
|
+
const aesNonce = aesWrapper.generateAESNonce();
|
|
10
10
|
const tohashed: string = "This is my array to encrypt";
|
|
11
11
|
const encoder = new TextEncoder();
|
|
12
12
|
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
@@ -19,7 +19,7 @@ describe("Symmetric Tests", () => {
|
|
|
19
19
|
it("aes 256 encrypt and decrypt equals", () => {
|
|
20
20
|
const aesWrapper: AESWrapper = new AESWrapper();
|
|
21
21
|
const aesKey = aesWrapper.aes256Key();
|
|
22
|
-
const aesNonce = aesWrapper.
|
|
22
|
+
const aesNonce = aesWrapper.generateAESNonce();
|
|
23
23
|
const tohashed: string = "This is my array to encrypt";
|
|
24
24
|
const encoder = new TextEncoder();
|
|
25
25
|
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|