Skip to content

Commit

Permalink
Merge pull request #32 from Cryptographic-API-Services/pre-release
Browse files Browse the repository at this point in the history
Pre release
  • Loading branch information
WingZer0o authored May 19, 2024
2 parents dd04911 + 1543f8f commit ed1e0c2
Show file tree
Hide file tree
Showing 43 changed files with 229 additions and 838 deletions.
20 changes: 3 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,13 @@ path = "src/lib.rs"
crate-type = ["cdylib"]

[dependencies]
aes-gcm = "0.10.3"
argon2 = "0.5.2"
bcrypt = "0.15.0"
blake2 = "0.10.6"
napi = "2"
napi-derive = "2"
rand = "0.8.5"
rand_chacha = "0.3.1"
rsa = "0.9.6"
scrypt = "0.11.0"
sha3 = "0.10.8"
x25519-dalek = {version = "2.0.0", features = ["static_secrets"]}
rand_07 = { package = "rand", version = "0.7.0" }
ascon-aead = "0.4.2"
rayon = "1.10.0"

[profile.dev.package.num-bigint-dig]
opt-level = 3

[dependencies.ed25519-dalek]
version = "1"
csbindgen = "1.9.1"
cas-lib = "0.1.3"

[build-dependencies]
napi-build = "1"
napi-build = "1"
43 changes: 22 additions & 21 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function sha512(dataToHash: Array<number>): Array<number>
export function sha512Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
export function sha256(dataToHash: Array<number>): Array<number>
export function sha256Verify(dataToHash: Array<number>, dataToVerify: Array<number>): boolean
export function x25519GenerateSecretAndPublicKey(): X25519SecretPublicKeyResult
export function x25519GenerateSecretAndPublicKey(): CASx25519SecretPublicKeyResult
export function x25519DiffieHellman(mySecretKey: Array<number>, usersPublicKey: Array<number>): Array<number>
export function aesNonce(): Array<number>
export function aes128Key(): Array<number>
Expand All @@ -28,52 +28,53 @@ export function aes128Encrypt(aesKey: Array<number>, nonce: Array<number>, plain
export function aes128Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>
export function aes256Encrypt(aesKey: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>
export function aes256Decrypt(aesKey: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>
export function aes256KeyFromX25519SharedSecret(sharedSecret: Array<number>): AesKeyFromX25519SharedSecret
export function aes128KeyFromX25519SharedSecret(sharedSecret: Array<number>): AesKeyFromX25519SharedSecret
export function generateRsaKeys(keySize: number): RsaKeyPairResult
export function aes256KeyFromX25519SharedSecret(sharedSecret: Array<number>): CASAesKeyFromX25519SharedSecret
export function aes128KeyFromX25519SharedSecret(sharedSecret: Array<number>): CASAesKeyFromX25519SharedSecret
export function generateRsaKeys(keySize: number): CasrsaKeyPairResult
export function encryptPlaintextRsa(publicKey: string, plaintext: Array<number>): Array<number>
export function decryptCiphertextRsa(privateKey: string, ciphertext: Array<number>): Array<number>
export function signRsa(privateKey: string, hash: Array<number>): Array<number>
export function verifyRsa(publicKey: string, hash: Array<number>, signature: Array<number>): boolean
export function sha512RsaDigitalSignature(rsaKeySize: number, dataToSign: Array<number>): RsaDigitalSignatureResult
export function sha512RsaDigitalSignature(rsaKeySize: number, dataToSign: Array<number>): CASRSADigitalSignatureResult
export function sha512RsaVerifyDigitalSignature(publicKey: string, dataToVerify: Array<number>, signature: Array<number>): boolean
export function sha256RsaDigitalSignature(rsaKeySize: number, dataToSign: Array<number>): RsaDigitalSignatureResult
export function sha256RsaDigitalSignature(rsaKeySize: number, dataToSign: Array<number>): CASRSADigitalSignatureResult
export function sha256RsaVerifyDigitalSignature(publicKey: string, dataToVerify: Array<number>, signature: Array<number>): boolean
export function sha512Ed25519DigitalSignature(dataToSign: Array<number>): Shaed25519DalekDigitalSignatureResult
export function sha512Ed25519DigitalSignature(dataToSign: Array<number>): CASSHAED25519DalekDigitalSignatureResult
export function sha512Ed25519DigitalSignatureVerify(publicKey: Array<number>, dataToVerify: Array<number>, signature: Array<number>): boolean
export function sha256Ed25519DigitalSignature(dataToSign: Array<number>): Shaed25519DalekDigitalSignatureResult
export function sha256Ed25519DigitalSignature(dataToSign: Array<number>): CASSHAED25519DalekDigitalSignatureResult
export function sha256Ed25519DigitalSignatureVerify(publicKey: Array<number>, dataToVerify: Array<number>, signature: Array<number>): boolean
export function ascon128KeyGenerate(): Array<number>
export function ascon128NonceGenerate(): Array<number>
export function ascon128Encrypt(key: Array<number>, nonce: Array<number>, plaintext: Array<number>): Array<number>
export function ascon128Decrypt(key: Array<number>, nonce: Array<number>, ciphertext: Array<number>): Array<number>
export type x25519SecretPublicKeyResult = X25519SecretPublicKeyResult
export class X25519SecretPublicKeyResult {
export type CASx25519SecretPublicKeyResult = CaSx25519SecretPublicKeyResult
export class CaSx25519SecretPublicKeyResult {
publicKey: Array<number>
secretKey: Array<number>
constructor(publicKey: Array<number>, secretKey: Array<number>)
}
export class AesKeyFromX25519SharedSecret {
export type CASAesKeyFromX25519SharedSecret = CasAesKeyFromX25519SharedSecret
export class CasAesKeyFromX25519SharedSecret {
aesKey: Array<number>
aesNonce: Array<number>
constructor(aesKey: Array<number>, aesNonce: Array<number>)
}
export type RSAKeyPairResult = RsaKeyPairResult
export class RsaKeyPairResult {
export type CASRSAKeyPairResult = CasrsaKeyPairResult
export class CasrsaKeyPairResult {
privateKey: string
publicKey: string
constructor(privateKey: string, publicKey: string)
}
export type RSADigitalSignatureResult = RsaDigitalSignatureResult
export class RsaDigitalSignatureResult {
export type CASSHAED25519DalekDigitalSignatureResult = Casshaed25519DalekDigitalSignatureResult
export class Casshaed25519DalekDigitalSignatureResult {
publicKey: Array<number>
signature: Array<number>
constructor(publicKey: Array<number>, signature: Array<number>)
}
export type CASRSADigitalSignatureResult = CasrsaDigitalSignatureResult
export class CasrsaDigitalSignatureResult {
publicKey: string
privateKey: string
signature: Array<number>
constructor(publicKey: string, privateKey: string, signature: Array<number>)
}
export type SHAED25519DalekDigitalSignatureResult = Shaed25519DalekDigitalSignatureResult
export class Shaed25519DalekDigitalSignatureResult {
publicKey: Array<number>
signature: Array<number>
constructor(publicKey: Array<number>, signature: Array<number>)
}
Binary file modified index.node
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

{
"name": "cas-typescript-sdk",
"version": "1.0.23",
"version": "1.0.24",
"description": "",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions src-ts/asymmetric/RSAWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { decryptCiphertextRsa, encryptPlaintextRsa, generateRsaKeys, RsaKeyPairResult, signRsa, verifyRsa } from "../../index";
import { CASRSAKeyPairResult, decryptCiphertextRsa, encryptPlaintextRsa, generateRsaKeys, signRsa, verifyRsa } from "../../index";

export class RSAWrapper {

/**
* Generates an RSA key pair based of parameter sent in 1024, 2048, and 4096 are supported.
* @param keySize
* @returns RsaKeyPairResult
* @returns CASRSAKeyPairResult
*/
public generateKeys(keySize: number): RsaKeyPairResult {
public generateKeys(keySize: number): CASRSAKeyPairResult {
if (keySize !== 1024 && keySize !== 2048 && keySize !== 4096) {
throw new Error("You must provide an appropriate key size to generate RSA keys");
}
Expand Down
4 changes: 2 additions & 2 deletions src-ts/asymmetric/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RSAWrapper } from "./RSAWrapper";
import { RsaKeyPairResult } from "../../index";
import { CASRSAKeyPairResult } from "../../index";

export { RSAWrapper, RsaKeyPairResult };
export { RSAWrapper, CASRSAKeyPairResult };
10 changes: 5 additions & 5 deletions src-ts/digital-signature/digital-siganture-sha-512.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { RsaDigitalSignatureResult, SHAED25519DalekDigitalSignatureResult, sha512Ed25519DigitalSignature, sha512Ed25519DigitalSignatureVerify, sha512RsaDigitalSignature, sha512RsaVerifyDigitalSignature } from "../../index";
import { CASRSADigitalSignatureResult, CASSHAED25519DalekDigitalSignatureResult, sha512Ed25519DigitalSignature, sha512Ed25519DigitalSignatureVerify, sha512RsaDigitalSignature, sha512RsaVerifyDigitalSignature } from "../../index";
import { IDigitalSignature } from "./digital-signature-base";

export class DigitalSignatureSHA512Wrapper implements IDigitalSignature {

/**
* Creates an ED25519 siganture from an array of bytes with SHA3-512.
* @param dataToSign
* @returns SHAED25519DalekDigitalSignatureResult
* @returns CASSHAED25519DalekDigitalSignatureResult
*/
createED25519(dataToSign: number[]): SHAED25519DalekDigitalSignatureResult {
createED25519(dataToSign: number[]): CASSHAED25519DalekDigitalSignatureResult {
if (dataToSign?.length === 0) {
throw new Error("Must provide allocated data to sign");
}
Expand Down Expand Up @@ -39,9 +39,9 @@ export class DigitalSignatureSHA512Wrapper implements IDigitalSignature {
* Generates and RSA digital signature with SHA3-512
* @param rsa_key_size
* @param data_to_sign
* @returns RsaDigitalSignatureResult
* @returns CASRSADigitalSignatureResult
*/
createRsa(rsa_key_size: number, data_to_sign: number[]): RsaDigitalSignatureResult {
createRsa(rsa_key_size: number, data_to_sign: number[]): CASRSADigitalSignatureResult {
if (rsa_key_size !== 1024 && rsa_key_size !== 2048 && rsa_key_size !== 4096) {
throw new Error("You need to provide an appropriate RSA key size.");
}
Expand Down
6 changes: 3 additions & 3 deletions src-ts/digital-signature/digital-signature-base.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { RSADigitalSignatureResult, SHAED25519DalekDigitalSignatureResult } from "../../index";
import { CASRSADigitalSignatureResult, CASSHAED25519DalekDigitalSignatureResult } from "../../index";

export interface IDigitalSignature {
createRsa(rsa_key_size: number, data_to_sign: Array<number>): RSADigitalSignatureResult;
createRsa(rsa_key_size: number, data_to_sign: Array<number>): CASRSADigitalSignatureResult;
verifyRSa(public_key: string, data_to_verify: Array<number>, signature: Array<number>): boolean;
createED25519(dataToSign: Array<number>): SHAED25519DalekDigitalSignatureResult;
createED25519(dataToSign: Array<number>): CASSHAED25519DalekDigitalSignatureResult;
verifyED25519(publicKey: Array<number>, dataToVerify: Array<number>, signature: Array<number>): boolean;
}
6 changes: 3 additions & 3 deletions src-ts/digital-signature/digital-signaturte-sha-256.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RsaDigitalSignatureResult, SHAED25519DalekDigitalSignatureResult, Shaed25519DalekDigitalSignatureResult, sha256Ed25519DigitalSignature, sha256Ed25519DigitalSignatureVerify, sha256RsaDigitalSignature, sha256RsaVerifyDigitalSignature, sha512Ed25519DigitalSignature } from "../../index";
import { CASRSADigitalSignatureResult, CASSHAED25519DalekDigitalSignatureResult, sha256Ed25519DigitalSignature, sha256Ed25519DigitalSignatureVerify, sha256RsaDigitalSignature, sha256RsaVerifyDigitalSignature, sha512Ed25519DigitalSignature } from "../../index";
import { IDigitalSignature } from "./digital-signature-base";

export class DigitalSignatureSHA256Wrapper implements IDigitalSignature {
Expand All @@ -8,7 +8,7 @@ export class DigitalSignatureSHA256Wrapper implements IDigitalSignature {
* @param dataToSign
* @returns SHAED25519DalekDigitalSignatureResult
*/
createED25519(dataToSign: number[]): Shaed25519DalekDigitalSignatureResult {
createED25519(dataToSign: number[]): CASSHAED25519DalekDigitalSignatureResult {
if (dataToSign?.length === 0) {
throw new Error("Must provide allocated data to sign");
}
Expand Down Expand Up @@ -41,7 +41,7 @@ export class DigitalSignatureSHA256Wrapper implements IDigitalSignature {
* @param data_to_sign
* @returns RsaDigitalSignatureResult
*/
createRsa(rsa_key_size: number, data_to_sign: number[]): RsaDigitalSignatureResult {
createRsa(rsa_key_size: number, data_to_sign: number[]): CASRSADigitalSignatureResult {
if (rsa_key_size !== 1024 && rsa_key_size !== 2048 && rsa_key_size !== 4096) {
throw new Error("You need to provide an appropriate RSA key size.");
}
Expand Down
5 changes: 4 additions & 1 deletion src-ts/digital-signature/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import { DigitalSignatureType } from "./digital-signature-factory";
import { DigitalSignatureFactory } from "./digital-signature-factory";
import { DigitalSignatureSHA256Wrapper } from "./digital-signaturte-sha-256";
import { DigitalSignatureSHA512Wrapper } from "./digital-siganture-sha-512";
import { CASRSADigitalSignatureResult, CASSHAED25519DalekDigitalSignatureResult } from "../../index";

export {
DigitalSignatureFactory,
DigitalSignatureSHA256Wrapper,
DigitalSignatureSHA512Wrapper,
DigitalSignatureType
DigitalSignatureType,
CASSHAED25519DalekDigitalSignatureResult,
CASRSADigitalSignatureResult
};
4 changes: 2 additions & 2 deletions src-ts/hybrid/types/aes-rsa-hybrid-initializer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { RsaKeyPairResult } from "../../..";
import { CASRSAKeyPairResult } from "../../..";
import { RSAWrapper } from "../../asymmetric";
import { AESWrapper } from "../../symmetric";

export class AESRSAHybridInitializer {
public aesType: number;
public aesKey: Array<number>;
public aesNonce: Array<number>;
public rsaKeyPair: RsaKeyPairResult;
public rsaKeyPair: CASRSAKeyPairResult;

/**
* 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.
Expand Down
54 changes: 8 additions & 46 deletions src-ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,8 @@
import {
Argon2Wrapper,
BCryptWrapper,
PasswordHasherFactory,
PasswordHasherType,
ScryptWrapper,
} from "./password-hashers/index";
import { HasherFactory, HasherType, SHAWrapper } from "./hashers/index";
import { X25519Wrapper } from "./key_exchange/index";
import { AESWrapper } from "./symmetric/index";
import { RsaKeyPairResult, RSAWrapper } from "./asymmetric/index";
import {
AesRsaHybridEncryptResult,
AESRSAHybridInitializer,
HybridEncryptionWrapper,
} from "./hybrid/index";
import {
DigitalSignatureFactory,
DigitalSignatureSHA256Wrapper,
DigitalSignatureSHA512Wrapper,
DigitalSignatureType,
} from "./digital-signature";
import { AsconWrapper } from "./sponges/index";

export {
AesRsaHybridEncryptResult,
AESRSAHybridInitializer,
AESWrapper,
Argon2Wrapper,
AsconWrapper,
BCryptWrapper,
DigitalSignatureFactory,
DigitalSignatureSHA256Wrapper,
DigitalSignatureSHA512Wrapper,
DigitalSignatureType,
HasherFactory,
HasherType,
HybridEncryptionWrapper,
PasswordHasherFactory,
PasswordHasherType,
RsaKeyPairResult,
RSAWrapper,
ScryptWrapper,
SHAWrapper,
X25519Wrapper,
};
export * from "./password-hashers/index";
export * from "./hashers/index";
export * from "./key_exchange/index";
export * from "./symmetric/index";
export * from "./asymmetric/index";
export * from "./hybrid/index";
export * from "./digital-signature";
export * from "./sponges/index";
3 changes: 2 additions & 1 deletion src-ts/key_exchange/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CASx25519SecretPublicKeyResult } from "../../index";
import { X25519Wrapper } from "./x25519";

export { X25519Wrapper };
export { X25519Wrapper, CASx25519SecretPublicKeyResult };
4 changes: 2 additions & 2 deletions src-ts/key_exchange/x25519.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { x25519DiffieHellman, x25519GenerateSecretAndPublicKey, X25519SecretPublicKeyResult } from "../../index"
import { CASx25519SecretPublicKeyResult, x25519DiffieHellman, x25519GenerateSecretAndPublicKey } from "../../index"

export class X25519Wrapper {
/**
* Generates and secret and public key to be used to create a shared secret with Diffie Hellman.
* 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.
* @returns X25519SecretPublicKeyResult
*/
public generateSecretAndPublicKey(): X25519SecretPublicKeyResult {
public generateSecretAndPublicKey(): CASx25519SecretPublicKeyResult {
return x25519GenerateSecretAndPublicKey();
}

Expand Down
6 changes: 3 additions & 3 deletions src-ts/symmetric/aes-wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
AesKeyFromX25519SharedSecret,
CASAesKeyFromX25519SharedSecret,
aes128Decrypt,
aes128Encrypt,
aes128Key,
Expand Down Expand Up @@ -87,7 +87,7 @@ export class AESWrapper {
* @param shared_secret
* @returns
*/
public aes256KeyNonceX25519DiffieHellman(shared_secret: Array<number>): AesKeyFromX25519SharedSecret {
public aes256KeyNonceX25519DiffieHellman(shared_secret: Array<number>): CASAesKeyFromX25519SharedSecret {
return aes256KeyFromX25519SharedSecret(shared_secret);
}

Expand All @@ -96,7 +96,7 @@ export class AESWrapper {
* @param shared_secret
* @returns
*/
public aes128KeyNonceX25519DiffieHellman(shared_secret: Array<number>): AesKeyFromX25519SharedSecret {
public aes128KeyNonceX25519DiffieHellman(shared_secret: Array<number>): CASAesKeyFromX25519SharedSecret {
return aes128KeyFromX25519SharedSecret(shared_secret);
}
}
3 changes: 2 additions & 1 deletion src-ts/symmetric/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CASAesKeyFromX25519SharedSecret } from "../../index";
import { AESWrapper } from "./aes-wrapper";

export { AESWrapper };
export { AESWrapper, CASAesKeyFromX25519SharedSecret };
15 changes: 0 additions & 15 deletions src/asymmetric/cas_asymmetric_encryption.rs

This file was deleted.

Loading

0 comments on commit ed1e0c2

Please sign in to comment.