UNPKG

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.

52 lines (51 loc) 1.89 kB
/** * @license * Copyright 2020 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import { Aead } from '../aead/internal/aead'; import { Mac } from '../mac/internal/mac'; import { IndCpaCipher } from './ind_cpa_cipher'; /** * This primitive performs an encrypt-then-Mac operation on plaintext and * additional authenticated data (aad). * * The Mac is computed over `aad || ciphertext || size of aad`, thus it * doesn't violate https://en.wikipedia.org/wiki/Horton_Principle. * * This implementation is based on * http://tools.ietf.org/html/draft-mcgrew-aead-aes-cbc-hmac-sha2-05. * * @final */ export declare class EncryptThenAuthenticate extends Aead { private readonly cipher; private readonly ivSize; private readonly mac; private readonly tagSize; /** * @param ivSize the IV size in bytes * @param tagSize the MAC tag size in bytes * @throws {InvalidArgumentsException} */ constructor(cipher: IndCpaCipher, ivSize: number, mac: Mac, tagSize: number); /** * The plaintext is encrypted with an {@link IndCpaCipher}, then MAC * is computed over `aad || ciphertext || t` where t is aad's length in bits * represented as 64-bit bigendian unsigned integer. The final ciphertext * format is `ind-cpa ciphertext || mac`. * */ encrypt(plaintext: Uint8Array, associatedData?: Uint8Array): Promise<Uint8Array>; /** */ decrypt(ciphertext: Uint8Array, associatedData?: Uint8Array): Promise<Uint8Array>; } /** * @param ivSize the size of the IV * @param hmacHashAlgo accepted names are SHA-1, SHA-256 and SHA-512 * @param tagSize the size of the tag * @throws {InvalidArgumentsException} * @static */ export declare function aesCtrHmacFromRawKeys(aesKey: Uint8Array, ivSize: number, hmacHashAlgo: string, hmacKey: Uint8Array, tagSize: number): Promise<EncryptThenAuthenticate>;