/**
 * Package newhope implements NewHope post-quantum key agreement function.
 */ import { RandomSource } from "@stablelib/random" ; import { SHAKE128 , SHA3256 } from "@stablelib/sha3" ; import { SeedExpander , CustomNewHope } from "./custom" ; export { PUBLIC_SEED_LENGTH , SECRET_SEED_LENGTH , OFFER_MESSAGE_LENGTH , ACCEPT_MESSAGE_LENGTH , SAVED_STATE_LENGTH } from "./custom" ; export const SHARED_KEY_LENGTH = 32 ; class SHAKE128Expander extends SHAKE128 implements SeedExpander { constructor ( seed ) { super ( ) ; this . update ( seed ) ; } } /**
 * NewHope provides post-quantum Ring-LWE-based key exchange between two peers.
 *
 * One peer generates an "offer message"" by calling offer(), and sends it to
 * the other peer. The other peer accepts the offer and generates "accept
 * message" by calling accept() with the received offer message. It then send
 * the result to the first peer, which calls finish(). After completing these
 * steps, both peers call getSharedKey() to get the established shared key.
 *
 * This is a reference version, which uses SHAKE-128 and SHA-3-256. You can
 * create a custom version by requiring "lib/custom" and extending
 * CustomNewHope class.
 *
 * Reference:
 *
 * Erdem Alkim, Léo Ducas, Thomas Pöppelmann, and Peter Schwabe: Post-quantum
 * key exchange – a new hope.
 *
 * https://cryptojedi.org/papers/#newhope
 */ export class NewHope extends CustomNewHope { constructor ( secretSeed ? , prng ? ) { super ( SHAKE128Expander , SHA3256 , SHARED_KEY_LENGTH , secretSeed , prng ) ; } }