tink-crypto
Version:
A multi-language, cross-platform library that provides cryptographic APIs that are secure, easy to use correctly, and hard(er) to misuse.
118 lines (117 loc) • 4.9 kB
TypeScript
/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { PbHpkeKem } from '../../../internal/proto';
import * as ellipticCurves from '../../../subtle/elliptic_curves';
/** HPKE mode identifiers. */
export declare const BASE_MODE: Uint8Array;
/** HPKE KEM algorithm identifier for P256 HKDF SHA256 KEM */
export declare const P256_HKDF_SHA256_KEM_ID: Uint8Array;
/** HPKE KEM algorithm identifier for P521 HKDF SHA512 KEM */
export declare const P521_HKDF_SHA512_KEM_ID: Uint8Array;
/** HPKE KDF algorithm identifier for HKDF SHA256 KDF */
export declare const HKDF_SHA256_KDF_ID: Uint8Array;
/** HPKE KDF algorithm identifier for HKDF SHA512 KDF */
export declare const HKDF_SHA512_KDF_ID: Uint8Array;
/** HPKE AEAD algorithm identifier for AES128 GCM */
export declare const AES_128_GCM_AEAD_ID: Uint8Array;
/** HPKE AEAD algorithm identifier for AES256 GCM */
export declare const AES_256_GCM_AEAD_ID: Uint8Array;
/** HPKE byte array representation for KEM */
export declare const KEM: Uint8Array;
/** HPKE byte array representation for KPKE */
export declare const HPKE: Uint8Array;
/** HPKE byte array representation for HPKE-v1 */
export declare const HPKE_V1: Uint8Array;
/**
* Transforms a passed value to an MSB first byte array with the size of the
* specified capacity.
*
* The HPKE standard defines this function as I2OSP(n, w) where w =
* capacity and n = value.
*
* @see https://www.rfc-editor.org/rfc/rfc9180.html#name-notation
*/
export declare function numberToByteArray(capacity: number, value: number): Uint8Array;
/**
* Transforms `value` to a MSB-first byte array of size `capacity`.
*
* The HPKE standard defines this function as I2OSP(n, w) where w =
* capacity and n = value.
*
* @see https://www.rfc-editor.org/rfc/rfc9180.html#name-notation
*
*/
export declare function bigIntToByteArray(capacity: number, value: bigint): Uint8Array;
/**
* Generates KEM suite id from `kemId` according to the definition in
* @see https://www.rfc-editor.org/rfc/rfc9180.html#section-4.1-5. Only used for
* KEM suite id.
* @throws SecurityException if byte concatenation fails.
*/
export declare function kemSuiteId(kemId: Uint8Array): Uint8Array;
/**
* Generates HPKE suite id from `kemId`, `kdfId`, and `aeadId` according to the
* definition in @see https://www.rfc-editor.org/rfc/rfc9180.html#section-5.1-8.
* Used for any non-KEM suite id.
* @throws a SecurityException if byte concatenation fails.
*/
export declare function hpkeSuiteId({ kemId, kdfId, aeadId }: {
kemId: Uint8Array;
kdfId: Uint8Array;
aeadId: Uint8Array;
}): Uint8Array;
/**
* Transforms `ikm` into labeled ikm using `label` and `suiteId` according to
* `LabeledExtract()` defined in
* @see https://www.rfc-editor.org/rfc/rfc9180.html#section-4.
* @throws an SecurityException if byte concatenation fails.
*/
export declare function labelIkm({ ikmLabel, ikm, suiteId }: {
ikmLabel: string;
ikm: Uint8Array;
suiteId: Uint8Array;
}): Uint8Array;
/**
* Transforms `info` into labeled info using `label`, `suiteId`, and `length`
* according to `LabeledExpand()` defined in
* @see https://www.rfc-editor.org/rfc/rfc9180.html#section-4.
* @throws a SecurityException if byte concatenation fails.
*/
export declare function labelInfo({ infoLabel, info, suiteId, length }: {
infoLabel: string;
info: Uint8Array;
suiteId: Uint8Array;
length: number;
}): Uint8Array;
/** Translates the NIST HPKE KEM identifier to the corresponding curve type */
export declare function nistHpkeKemToCurve(kem: PbHpkeKem): ellipticCurves.CurveType.P256 | ellipticCurves.CurveType.P521;
/**
* Performs the uncompressed string (given as `key` in the form of a byte array)
* to elliptic curve (given via (string) `curveType`) point conversion according
* to Section 2.3.3 of https://secg.org/sec1-v2.pdf and returns the result as a
* CryptoKey.
*/
export declare function getPublicKeyFromByteArray(curveType: string, key: Uint8Array): Promise<CryptoKey>;
/**
* Converts `{curveType, publicKey, privateKey}`, into a private `CryptoKey`.
*
* The `publicKey` is an uncompressed point encoded according to
* Section 2.3.3 of @see https://secg.org/sec1-v2.pdf. The `privateKey` is a
* large integer encoded according to Section 2.3.5 of
* @see https://secg.org/sec1-v2.pdf. `curveType` is the the string
* representation of the elliptic curve on which to perform the conversion.
*/
export declare function getPrivateKeyFromByteArray({ curveType, publicKey, privateKey }: {
curveType: string;
publicKey: Uint8Array;
privateKey: Uint8Array;
}): Promise<CryptoKey>;
/**
* Converts a public `key` into a `Uint8Array` containing an
* uncompressed point encoded according to Section 2.3.3 of
* @see https://secg.org/sec1-v2.pdf.
*/
export declare function getByteArrayFromPublicKey(key: CryptoKey): Promise<Uint8Array>;