Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/crypto/openssl/ossl_aes_gcm.h
39478 views
1
/*-
2
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3
*
4
* Copyright (c) 2023 Stormshield
5
*
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions
8
* are met:
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
*
15
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
*/
26
27
#ifndef _OSSL_AES_GCM_H_
28
#define _OSSL_AES_GCM_H_
29
30
#include <crypto/openssl/ossl_cipher.h>
31
32
struct ossl_gcm_context;
33
34
struct ossl_aes_gcm_ops {
35
void (*init)(struct ossl_gcm_context *ctx, const void *key,
36
size_t keylen);
37
void (*setiv)(struct ossl_gcm_context *ctx, const unsigned char *iv,
38
size_t ivlen);
39
int (*aad)(struct ossl_gcm_context *ctx, const unsigned char *aad,
40
size_t len);
41
int (*encrypt)(struct ossl_gcm_context *ctx, const unsigned char *in,
42
unsigned char *out, size_t len);
43
int (*decrypt)(struct ossl_gcm_context *ctx, const unsigned char *in,
44
unsigned char *out, size_t len);
45
int (*finish)(struct ossl_gcm_context *ctx, const unsigned char *tag,
46
size_t len);
47
void (*tag)(struct ossl_gcm_context *ctx, unsigned char *tag,
48
size_t len);
49
};
50
51
#ifndef __SIZEOF_INT128__
52
typedef struct { uint64_t v[2]; } __uint128_t;
53
#endif
54
55
struct ossl_gcm_context {
56
struct {
57
union {
58
uint64_t u[2];
59
uint32_t d[4];
60
uint8_t c[16];
61
} Yi, EKi, EK0, len, Xi, H;
62
__uint128_t Htable[16];
63
unsigned int mres, ares;
64
} gcm;
65
66
struct ossl_aes_keysched aes_ks;
67
68
const struct ossl_aes_gcm_ops *ops;
69
};
70
71
#endif /* !_OSSL_AES_GCM_H_ */
72
73