decrepit/cfb/cfb.c
Go to the documentation of this file.
1 // Copyright (c) 2017, Google Inc.
2 //
3 // Permission to use, copy, modify, and/or distribute this software for any
4 // purpose with or without fee is hereby granted, provided that the above
5 // copyright notice and this permission notice appear in all copies.
6 //
7 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10 // SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12 // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13 // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14 
15 #include <openssl/cipher.h>
16 
17 #include <string.h>
18 
19 #include <openssl/aes.h>
20 #include <openssl/obj.h>
21 
22 #include "../../crypto/internal.h"
23 
24 typedef struct {
26 } EVP_CFB_CTX;
27 
29  const uint8_t *iv, int enc) {
30  if (key) {
31  EVP_CFB_CTX *cfb_ctx = ctx->cipher_data;
32  AES_set_encrypt_key(key, ctx->key_len * 8, &cfb_ctx->ks);
33  }
34 
35  return 1;
36 }
37 
39  const uint8_t *in, size_t len) {
40  if (!out || !in) {
41  return 0;
42  }
43 
44  EVP_CFB_CTX *cfb_ctx = ctx->cipher_data;
45  int num = ctx->num;
46  AES_cfb128_encrypt(in, out, len, &cfb_ctx->ks, ctx->iv, &num,
47  ctx->encrypt ? AES_ENCRYPT : AES_DECRYPT);
48  ctx->num = num;
49 
50  return 1;
51 }
52 
53 static const EVP_CIPHER aes_128_cfb128 = {
54  NID_aes_128_cfb128, 1 /* block_size */, 16 /* key_size */,
55  16 /* iv_len */, sizeof(EVP_CFB_CTX), EVP_CIPH_CFB_MODE,
56  NULL /* app_data */, aes_cfb_init_key, aes_cfb128_cipher,
57  NULL /* cleanup */, NULL /* ctrl */,
58 };
59 
60 static const EVP_CIPHER aes_192_cfb128 = {
61  NID_aes_192_cfb128, 1 /* block_size */, 24 /* key_size */,
62  16 /* iv_len */, sizeof(EVP_CFB_CTX), EVP_CIPH_CFB_MODE,
63  NULL /* app_data */, aes_cfb_init_key, aes_cfb128_cipher,
64  NULL /* cleanup */, NULL /* ctrl */,
65 };
66 
67 static const EVP_CIPHER aes_256_cfb128 = {
68  NID_aes_256_cfb128, 1 /* block_size */, 32 /* key_size */,
69  16 /* iv_len */, sizeof(EVP_CFB_CTX), EVP_CIPH_CFB_MODE,
70  NULL /* app_data */, aes_cfb_init_key, aes_cfb128_cipher,
71  NULL /* cleanup */, NULL /* ctrl */,
72 };
73 
74 const EVP_CIPHER *EVP_aes_128_cfb128(void) { return &aes_128_cfb128; }
75 const EVP_CIPHER *EVP_aes_128_cfb(void) { return &aes_128_cfb128; }
76 const EVP_CIPHER *EVP_aes_192_cfb128(void) { return &aes_192_cfb128; }
77 const EVP_CIPHER *EVP_aes_192_cfb(void) { return &aes_192_cfb128; }
78 const EVP_CIPHER *EVP_aes_256_cfb128(void) { return &aes_256_cfb128; }
79 const EVP_CIPHER *EVP_aes_256_cfb(void) { return &aes_256_cfb128; }
AES_ENCRYPT
#define AES_ENCRYPT
Definition: aes.h:62
aes_cfb128_cipher
static int aes_cfb128_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in, size_t len)
Definition: decrepit/cfb/cfb.c:38
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
AES_set_encrypt_key
#define AES_set_encrypt_key
Definition: boringssl_prefix_symbols.h:603
ctx
Definition: benchmark-async.c:30
EVP_aes_192_cfb
const EVP_CIPHER * EVP_aes_192_cfb(void)
Definition: decrepit/cfb/cfb.c:77
aes_192_cfb128
static const EVP_CIPHER aes_192_cfb128
Definition: decrepit/cfb/cfb.c:60
NID_aes_256_cfb128
#define NID_aes_256_cfb128
Definition: nid.h:1983
aes_256_cfb128
static const EVP_CIPHER aes_256_cfb128
Definition: decrepit/cfb/cfb.c:67
EVP_aes_128_cfb128
const EVP_CIPHER * EVP_aes_128_cfb128(void)
Definition: decrepit/cfb/cfb.c:74
string.h
AES_cfb128_encrypt
#define AES_cfb128_encrypt
Definition: boringssl_prefix_symbols.h:596
EVP_aes_128_cfb
const EVP_CIPHER * EVP_aes_128_cfb(void)
Definition: decrepit/cfb/cfb.c:75
aes_cfb_init_key
static int aes_cfb_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key, const uint8_t *iv, int enc)
Definition: decrepit/cfb/cfb.c:28
EVP_aes_256_cfb128
const EVP_CIPHER * EVP_aes_256_cfb128(void)
Definition: decrepit/cfb/cfb.c:78
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
evp_cipher_ctx_st
Definition: cipher.h:536
NID_aes_128_cfb128
#define NID_aes_128_cfb128
Definition: nid.h:1943
EVP_aes_256_cfb
const EVP_CIPHER * EVP_aes_256_cfb(void)
Definition: decrepit/cfb/cfb.c:79
NID_aes_192_cfb128
#define NID_aes_192_cfb128
Definition: nid.h:1963
in
const char * in
Definition: third_party/abseil-cpp/absl/strings/internal/str_format/parser_test.cc:391
evp_cipher_st
Definition: cipher.h:585
aes.h
cipher.h
EVP_aes_192_cfb128
const EVP_CIPHER * EVP_aes_192_cfb128(void)
Definition: decrepit/cfb/cfb.c:76
aes_128_cfb128
static const EVP_CIPHER aes_128_cfb128
Definition: decrepit/cfb/cfb.c:53
EVP_CIPH_CFB_MODE
#define EVP_CIPH_CFB_MODE
Definition: cipher.h:346
EVP_CFB_CTX::ks
AES_KEY ks
Definition: decrepit/cfb/cfb.c:25
key
const char * key
Definition: hpack_parser_table.cc:164
AES_DECRYPT
#define AES_DECRYPT
Definition: aes.h:63
xds_manager.num
num
Definition: xds_manager.py:56
obj.h
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
aes_key_st
Definition: aes.h:72
EVP_CFB_CTX
Definition: decrepit/cfb/cfb.c:24


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:52