Comparing version 0.3.0 to 0.4.0
@@ -17,3 +17,3 @@ { | ||
}, | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "A public-private key library for post-quantum cryptography (early stage, use with caution)", | ||
@@ -20,0 +20,0 @@ "bugs": { |
import { ml_kem512 } from "@noble/post-quantum/ml-kem"; | ||
import { Buffer } from "buffer"; //for web | ||
const VERSION = 3; //incremental versions, each one is not compatible with earlier ones. | ||
const VERSION = 4; //incremental versions, each one is not compatible with earlier ones. | ||
function makeBigInt(arr: number[]): string { | ||
let bigInt = BigInt(0); | ||
for (let i = 0; i < arr.length; i++) { | ||
bigInt = (bigInt << BigInt(8)) | BigInt(arr[i]); | ||
} | ||
return `${bigInt}`; | ||
} | ||
function makeArray(bas: string) { | ||
let b = BigInt(bas); | ||
const arr = []; | ||
while (b > 0) { | ||
arr.unshift(Number(b & BigInt(0xFF))); | ||
b >>= BigInt(8); | ||
} | ||
return arr; | ||
} | ||
interface SIGN { | ||
@@ -61,4 +84,4 @@ publicKeyBytes: Promise<number>; | ||
version: VERSION, | ||
kyberPublicKey: Array.from(kyberKeyPair.publicKey), | ||
falconPublicKey: Array.from(falconKeyPair.publicKey), | ||
kyberPublicKey: makeBigInt(Array.from(kyberKeyPair.publicKey)), | ||
falconPublicKey: makeBigInt(Array.from(falconKeyPair.publicKey)), | ||
}; | ||
@@ -68,4 +91,4 @@ | ||
version: VERSION, | ||
kyberPrivateKey: Array.from(kyberKeyPair.secretKey), | ||
falconPrivateKey: Array.from(falconKeyPair.privateKey), | ||
kyberPrivateKey: makeBigInt(Array.from(kyberKeyPair.secretKey)), | ||
falconPrivateKey: makeBigInt(Array.from(falconKeyPair.privateKey)), | ||
}; | ||
@@ -104,3 +127,3 @@ | ||
const publicKeyObj = JSON.parse(Buffer.from(publicKeyEncoded, "base64").toString("utf-8")); | ||
const kyberPublicKey = new Uint8Array(publicKeyObj.kyberPublicKey); | ||
const kyberPublicKey = new Uint8Array(makeArray(publicKeyObj.kyberPublicKey)); | ||
@@ -165,4 +188,4 @@ // Encapsulate shared secret using Kyber | ||
const privateKeyObj = JSON.parse(Buffer.from(privateKeyEncoded, "base64").toString("utf-8")); | ||
const kyberPrivateKey = new Uint8Array(privateKeyObj.kyberPrivateKey); | ||
const kyberPrivateKey = new Uint8Array(makeArray(privateKeyObj.kyberPrivateKey)); | ||
//decapsulate shared secret using Kyber | ||
@@ -209,3 +232,3 @@ const sharedSecret = ml_kem512.decapsulate(cipherText, kyberPrivateKey); | ||
const privateKeyObj = JSON.parse(Buffer.from(privateKeyEncoded, "base64").toString("utf-8")); | ||
const falconPrivateKey = new Uint8Array(privateKeyObj.falconPrivateKey); | ||
const falconPrivateKey = new Uint8Array(makeArray(privateKeyObj.falconPrivateKey)); | ||
@@ -245,3 +268,3 @@ //sign using FALCON-512 | ||
const publicKeyObj = JSON.parse(Buffer.from(publicKeyEncoded, "base64").toString("utf-8")); | ||
const falconPublicKey = new Uint8Array(publicKeyObj.falconPublicKey); | ||
const falconPublicKey = new Uint8Array(makeArray(publicKeyObj.falconPublicKey)); | ||
@@ -248,0 +271,0 @@ //initialize Falcon signing |
@@ -6,2 +6,6 @@ import { createKeyPair, decrypt, encrypt, sign, verify } from "."; | ||
console.log(`key length: ${aliceKeys.privateKey.length}, ${aliceKeys.publicKey.length}`); | ||
console.log(aliceKeys.publicKey); | ||
const message = "Cool beans"; | ||
@@ -8,0 +12,0 @@ |
22402
313