]> git.ipfire.org Git - thirdparty/openssl.git/blob - providers/common/ciphers/ciphers_locl.h
Structure alignment macro.
[thirdparty/openssl.git] / providers / common / ciphers / ciphers_locl.h
1
2 /*
3 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
4 *
5 * Licensed under the Apache License 2.0 (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
9 */
10
11 #include <openssl/aes.h>
12 #include <openssl/modes.h>
13 #include "internal/cryptlib.h"
14
15 typedef struct prov_aes_cipher_st PROV_AES_CIPHER;
16
17 typedef struct prov_aes_key_st {
18 union {
19 OSSL_UNION_ALIGN;
20 AES_KEY ks;
21 } ks;
22 block128_f block;
23 union {
24 cbc128_f cbc;
25 ctr128_f ctr;
26 } stream;
27
28 /* Platform specific data */
29 union {
30 int dummy;
31 #if defined(OPENSSL_CPUID_OBJ) && defined(__s390__)
32 struct {
33 union {
34 OSSL_UNION_ALIGN;
35 /*-
36 * KM-AES parameter block - begin
37 * (see z/Architecture Principles of Operation >= SA22-7832-06)
38 */
39 struct {
40 unsigned char k[32];
41 } km;
42 /* KM-AES parameter block - end */
43 /*-
44 * KMO-AES/KMF-AES parameter block - begin
45 * (see z/Architecture Principles of Operation >= SA22-7832-08)
46 */
47 struct {
48 unsigned char cv[16];
49 unsigned char k[32];
50 } kmo_kmf;
51 /* KMO-AES/KMF-AES parameter block - end */
52 } param;
53 unsigned int fc;
54 int res;
55 } s390x;
56 #endif /* defined(OPENSSL_CPUID_OBJ) && defined(__s390__) */
57 } plat;
58
59 /* The cipher functions we are going to use */
60 const PROV_AES_CIPHER *ciph;
61
62 /* The mode that we are using */
63 int mode;
64
65 /* Set to 1 if we are encrypting or 0 otherwise */
66 int enc;
67
68 unsigned char iv[AES_BLOCK_SIZE];
69
70 /*
71 * num contains the number of bytes of |iv| which are valid for modes that
72 * manage partial blocks themselves.
73 */
74 size_t num;
75
76 /* Buffer of partial blocks processed via update calls */
77 unsigned char buf[AES_BLOCK_SIZE];
78
79 /* Number of bytes in buf */
80 size_t bufsz;
81
82 uint64_t flags;
83
84 size_t keylen;
85
86 /* Whether padding should be used or not */
87 unsigned int pad : 1;
88 } PROV_AES_KEY;
89
90 struct prov_aes_cipher_st {
91 int (*init)(PROV_AES_KEY *dat, const uint8_t *key, size_t keylen);
92 int (*cipher)(PROV_AES_KEY *dat, uint8_t *out, const uint8_t *in,
93 size_t inl);
94 };
95
96 const PROV_AES_CIPHER *PROV_AES_CIPHER_ecb(size_t keylen);
97 const PROV_AES_CIPHER *PROV_AES_CIPHER_cbc(size_t keylen);
98 const PROV_AES_CIPHER *PROV_AES_CIPHER_ofb(size_t keylen);
99 const PROV_AES_CIPHER *PROV_AES_CIPHER_cfb(size_t keylen);
100 const PROV_AES_CIPHER *PROV_AES_CIPHER_cfb1(size_t keylen);
101 const PROV_AES_CIPHER *PROV_AES_CIPHER_cfb8(size_t keylen);
102 const PROV_AES_CIPHER *PROV_AES_CIPHER_ctr(size_t keylen);
103
104 size_t fillblock(unsigned char *buf, size_t *buflen, size_t blocksize,
105 const unsigned char **in, size_t *inlen);
106 int trailingdata(unsigned char *buf, size_t *buflen, size_t blocksize,
107 const unsigned char **in, size_t *inlen);
108 void padblock(unsigned char *buf, size_t *buflen, size_t blocksize);
109 int unpadblock(unsigned char *buf, size_t *buflen, size_t blocksize);