1 /* $OpenBSD: modes.h,v 1.6 2023/07/08 14:55:36 beck Exp $ */ 2 /* ==================================================================== 3 * Copyright (c) 2008 The OpenSSL Project. All rights reserved. 4 * 5 * Rights for redistribution and usage in source and binary 6 * forms are granted according to the OpenSSL license. 7 */ 8 9 #include <stddef.h> 10 11 #ifdef __cplusplus 12 extern "C" { 13 #endif 14 15 typedef void (*block128_f)(const unsigned char in[16], 16 unsigned char out[16], 17 const void *key); 18 19 typedef void (*cbc128_f)(const unsigned char *in, unsigned char *out, 20 size_t len, const void *key, 21 unsigned char ivec[16], int enc); 22 23 typedef void (*ctr128_f)(const unsigned char *in, unsigned char *out, 24 size_t blocks, const void *key, 25 const unsigned char ivec[16]); 26 27 typedef void (*ccm128_f)(const unsigned char *in, unsigned char *out, 28 size_t blocks, const void *key, 29 const unsigned char ivec[16], unsigned char cmac[16]); 30 31 void CRYPTO_cbc128_encrypt(const unsigned char *in, unsigned char *out, 32 size_t len, const void *key, 33 unsigned char ivec[16], block128_f block); 34 void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out, 35 size_t len, const void *key, 36 unsigned char ivec[16], block128_f block); 37 38 void CRYPTO_ctr128_encrypt(const unsigned char *in, unsigned char *out, 39 size_t len, const void *key, 40 unsigned char ivec[16], unsigned char ecount_buf[16], 41 unsigned int *num, block128_f block); 42 43 void CRYPTO_ctr128_encrypt_ctr32(const unsigned char *in, unsigned char *out, 44 size_t len, const void *key, 45 unsigned char ivec[16], unsigned char ecount_buf[16], 46 unsigned int *num, ctr128_f ctr); 47 48 void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out, 49 size_t len, const void *key, 50 unsigned char ivec[16], int *num, 51 block128_f block); 52 53 void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out, 54 size_t len, const void *key, 55 unsigned char ivec[16], int *num, 56 int enc, block128_f block); 57 void CRYPTO_cfb128_8_encrypt(const unsigned char *in, unsigned char *out, 58 size_t length, const void *key, 59 unsigned char ivec[16], int *num, 60 int enc, block128_f block); 61 void CRYPTO_cfb128_1_encrypt(const unsigned char *in, unsigned char *out, 62 size_t bits, const void *key, 63 unsigned char ivec[16], int *num, 64 int enc, block128_f block); 65 66 typedef struct gcm128_context GCM128_CONTEXT; 67 68 GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block); 69 void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, void *key, block128_f block); 70 void CRYPTO_gcm128_setiv(GCM128_CONTEXT *ctx, const unsigned char *iv, 71 size_t len); 72 int CRYPTO_gcm128_aad(GCM128_CONTEXT *ctx, const unsigned char *aad, 73 size_t len); 74 int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx, 75 const unsigned char *in, unsigned char *out, 76 size_t len); 77 int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx, 78 const unsigned char *in, unsigned char *out, 79 size_t len); 80 int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx, 81 const unsigned char *in, unsigned char *out, 82 size_t len, ctr128_f stream); 83 int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx, 84 const unsigned char *in, unsigned char *out, 85 size_t len, ctr128_f stream); 86 int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx, const unsigned char *tag, 87 size_t len); 88 void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, unsigned char *tag, size_t len); 89 void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx); 90 91 typedef struct ccm128_context CCM128_CONTEXT; 92 93 void CRYPTO_ccm128_init(CCM128_CONTEXT *ctx, 94 unsigned int M, unsigned int L, void *key, block128_f block); 95 int CRYPTO_ccm128_setiv(CCM128_CONTEXT *ctx, 96 const unsigned char *nonce, size_t nlen, size_t mlen); 97 void CRYPTO_ccm128_aad(CCM128_CONTEXT *ctx, 98 const unsigned char *aad, size_t alen); 99 int CRYPTO_ccm128_encrypt(CCM128_CONTEXT *ctx, 100 const unsigned char *inp, unsigned char *out, size_t len); 101 int CRYPTO_ccm128_decrypt(CCM128_CONTEXT *ctx, 102 const unsigned char *inp, unsigned char *out, size_t len); 103 int CRYPTO_ccm128_encrypt_ccm64(CCM128_CONTEXT *ctx, 104 const unsigned char *inp, unsigned char *out, size_t len, 105 ccm128_f stream); 106 int CRYPTO_ccm128_decrypt_ccm64(CCM128_CONTEXT *ctx, 107 const unsigned char *inp, unsigned char *out, size_t len, 108 ccm128_f stream); 109 size_t CRYPTO_ccm128_tag(CCM128_CONTEXT *ctx, unsigned char *tag, size_t len); 110 111 typedef struct xts128_context XTS128_CONTEXT; 112 113 int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16], 114 const unsigned char *inp, unsigned char *out, size_t len, int enc); 115 116 #ifdef __cplusplus 117 } 118 #endif 119