Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:14

0001 /* cbc.h
0002 
0003    Cipher block chaining mode.
0004 
0005    Copyright (C) 2001 Niels Möller
0006 
0007    This file is part of GNU Nettle.
0008 
0009    GNU Nettle is free software: you can redistribute it and/or
0010    modify it under the terms of either:
0011 
0012      * the GNU Lesser General Public License as published by the Free
0013        Software Foundation; either version 3 of the License, or (at your
0014        option) any later version.
0015 
0016    or
0017 
0018      * the GNU General Public License as published by the Free
0019        Software Foundation; either version 2 of the License, or (at your
0020        option) any later version.
0021 
0022    or both in parallel, as here.
0023 
0024    GNU Nettle is distributed in the hope that it will be useful,
0025    but WITHOUT ANY WARRANTY; without even the implied warranty of
0026    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0027    General Public License for more details.
0028 
0029    You should have received copies of the GNU General Public License and
0030    the GNU Lesser General Public License along with this program.  If
0031    not, see http://www.gnu.org/licenses/.
0032 */
0033 
0034 #ifndef NETTLE_CBC_H_INCLUDED
0035 #define NETTLE_CBC_H_INCLUDED
0036 
0037 #include "nettle-types.h"
0038 #include "aes.h"
0039 
0040 #ifdef __cplusplus
0041 extern "C" {
0042 #endif
0043 
0044 /* Name mangling */
0045 #define cbc_encrypt nettle_cbc_encrypt
0046 #define cbc_decrypt nettle_cbc_decrypt
0047 #define cbc_aes128_encrypt nettle_cbc_aes128_encrypt
0048 #define cbc_aes192_encrypt nettle_cbc_aes192_encrypt
0049 #define cbc_aes256_encrypt nettle_cbc_aes256_encrypt
0050 
0051 void
0052 cbc_encrypt(const void *ctx, nettle_cipher_func *f,
0053         size_t block_size, uint8_t *iv,
0054         size_t length, uint8_t *dst,
0055         const uint8_t *src);
0056 
0057 void
0058 cbc_decrypt(const void *ctx, nettle_cipher_func *f,
0059         size_t block_size, uint8_t *iv,
0060         size_t length, uint8_t *dst,
0061         const uint8_t *src);
0062 
0063 #define CBC_CTX(type, size) \
0064 { type ctx; uint8_t iv[size]; }
0065 
0066 #define CBC_SET_IV(ctx, data) \
0067 memcpy((ctx)->iv, (data), sizeof((ctx)->iv))
0068 
0069 /* NOTE: Avoid using NULL, as we don't include anything defining it. */
0070 #define CBC_ENCRYPT(self, f, length, dst, src)      \
0071   (0 ? ((f)(&(self)->ctx, ~(size_t) 0,          \
0072         (uint8_t *) 0, (const uint8_t *) 0))    \
0073    : cbc_encrypt((void *) &(self)->ctx,         \
0074          (nettle_cipher_func *) (f),        \
0075          sizeof((self)->iv), (self)->iv,    \
0076          (length), (dst), (src)))
0077 
0078 #define CBC_DECRYPT(self, f, length, dst, src)      \
0079   (0 ? ((f)(&(self)->ctx, ~(size_t) 0,          \
0080         (uint8_t *) 0, (const uint8_t *) 0))    \
0081    : cbc_decrypt((void *) &(self)->ctx,         \
0082          (nettle_cipher_func *) (f),        \
0083          sizeof((self)->iv), (self)->iv,    \
0084          (length), (dst), (src)))
0085 
0086 void
0087 cbc_aes128_encrypt(const struct aes128_ctx *ctx, uint8_t *iv,
0088            size_t length, uint8_t *dst, const uint8_t *src);
0089 
0090 void
0091 cbc_aes192_encrypt(const struct aes192_ctx *ctx, uint8_t *iv,
0092            size_t length, uint8_t *dst, const uint8_t *src);
0093 
0094 void
0095 cbc_aes256_encrypt(const struct aes256_ctx *ctx, uint8_t *iv,
0096            size_t length, uint8_t *dst, const uint8_t *src);
0097 
0098 #ifdef __cplusplus
0099 }
0100 #endif
0101 
0102 #endif /* NETTLE_CBC_H_INCLUDED */