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