19a3444d9SMark Johnston /*- 29a3444d9SMark Johnston * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 39a3444d9SMark Johnston * 49a3444d9SMark Johnston * Copyright (c) 2023 Stormshield 59a3444d9SMark Johnston * 69a3444d9SMark Johnston * Redistribution and use in source and binary forms, with or without 79a3444d9SMark Johnston * modification, are permitted provided that the following conditions 89a3444d9SMark Johnston * are met: 99a3444d9SMark Johnston * 1. Redistributions of source code must retain the above copyright 109a3444d9SMark Johnston * notice, this list of conditions and the following disclaimer. 119a3444d9SMark Johnston * 2. Redistributions in binary form must reproduce the above copyright 129a3444d9SMark Johnston * notice, this list of conditions and the following disclaimer in the 139a3444d9SMark Johnston * documentation and/or other materials provided with the distribution. 149a3444d9SMark Johnston * 159a3444d9SMark Johnston * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 169a3444d9SMark Johnston * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 179a3444d9SMark Johnston * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 189a3444d9SMark Johnston * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 199a3444d9SMark Johnston * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 209a3444d9SMark Johnston * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 219a3444d9SMark Johnston * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 229a3444d9SMark Johnston * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 239a3444d9SMark Johnston * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 249a3444d9SMark Johnston * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 259a3444d9SMark Johnston */ 269a3444d9SMark Johnston 279a3444d9SMark Johnston #ifndef _OSSL_AES_GCM_H_ 289a3444d9SMark Johnston #define _OSSL_AES_GCM_H_ 299a3444d9SMark Johnston 309a3444d9SMark Johnston #include <crypto/openssl/ossl_cipher.h> 319a3444d9SMark Johnston 329a3444d9SMark Johnston struct ossl_gcm_context; 339a3444d9SMark Johnston 349a3444d9SMark Johnston struct ossl_aes_gcm_ops { 359a3444d9SMark Johnston void (*init)(struct ossl_gcm_context *ctx, const void *key, 369a3444d9SMark Johnston size_t keylen); 379a3444d9SMark Johnston void (*setiv)(struct ossl_gcm_context *ctx, const unsigned char *iv, 389a3444d9SMark Johnston size_t ivlen); 399a3444d9SMark Johnston int (*aad)(struct ossl_gcm_context *ctx, const unsigned char *aad, 409a3444d9SMark Johnston size_t len); 419a3444d9SMark Johnston int (*encrypt)(struct ossl_gcm_context *ctx, const unsigned char *in, 429a3444d9SMark Johnston unsigned char *out, size_t len); 439a3444d9SMark Johnston int (*decrypt)(struct ossl_gcm_context *ctx, const unsigned char *in, 449a3444d9SMark Johnston unsigned char *out, size_t len); 459a3444d9SMark Johnston int (*finish)(struct ossl_gcm_context *ctx, const unsigned char *tag, 469a3444d9SMark Johnston size_t len); 479a3444d9SMark Johnston void (*tag)(struct ossl_gcm_context *ctx, unsigned char *tag, 489a3444d9SMark Johnston size_t len); 499a3444d9SMark Johnston }; 509a3444d9SMark Johnston 519d5a47e1SMark Johnston #ifndef __SIZEOF_INT128__ 529d5a47e1SMark Johnston typedef struct { uint64_t v[2]; } __uint128_t; 539d5a47e1SMark Johnston #endif 549d5a47e1SMark Johnston 559a3444d9SMark Johnston struct ossl_gcm_context { 569a3444d9SMark Johnston struct { 579a3444d9SMark Johnston union { 589a3444d9SMark Johnston uint64_t u[2]; 599a3444d9SMark Johnston uint32_t d[4]; 609a3444d9SMark Johnston uint8_t c[16]; 619a3444d9SMark Johnston } Yi, EKi, EK0, len, Xi, H; 629a3444d9SMark Johnston __uint128_t Htable[16]; 639a3444d9SMark Johnston unsigned int mres, ares; 649a3444d9SMark Johnston } gcm; 659a3444d9SMark Johnston 66*44f8e1e8SMark Johnston struct ossl_aes_keysched aes_ks; 679a3444d9SMark Johnston 689a3444d9SMark Johnston const struct ossl_aes_gcm_ops *ops; 699a3444d9SMark Johnston }; 709a3444d9SMark Johnston 719a3444d9SMark Johnston #endif /* !_OSSL_AES_GCM_H_ */ 72