1 /* 2 * cifra - embedded cryptography library 3 * Written in 2014 by Joseph Birr-Pixton <jpixton@gmail.com> 4 * 5 * To the extent possible under law, the author(s) have dedicated all 6 * copyright and related and neighboring rights to this software to the 7 * public domain worldwide. This software is distributed without any 8 * warranty. 9 * 10 * You should have received a copy of the CC0 Public Domain Dedication 11 * along with this software. If not, see 12 * <http://creativecommons.org/publicdomain/zero/1.0/>. 13 */ 14 15 #ifndef PRP_H 16 #define PRP_H 17 18 #include <stddef.h> 19 #include <stdint.h> 20 21 /** 22 * General block cipher description 23 * ================================ 24 * This allows us to implement block cipher modes which can work 25 * with different block ciphers. 26 */ 27 28 /* .. c:type:: cf_prp_block 29 * Block processing function type. 30 * 31 * The `in` and `out` blocks may alias. 32 * 33 * :rtype: void 34 * :param ctx: block cipher-specific context object. 35 * :param in: input block. 36 * :param out: output block. 37 */ 38 typedef void (*cf_prp_block)(void *ctx, const uint8_t *in, uint8_t *out); 39 40 /* .. c:type:: cf_prp 41 * Describes an PRP in a general way. 42 * 43 * .. c:member:: cf_prp.blocksz 44 * Block size in bytes. Must be no more than :c:macro:`CF_MAXBLOCK`. 45 * 46 * .. c:member:: cf_prp.encrypt 47 * Block encryption function. 48 * 49 * .. c:member:: cf_prp.decrypt 50 * Block decryption function. 51 */ 52 typedef struct 53 { 54 size_t blocksz; 55 cf_prp_block encrypt; 56 cf_prp_block decrypt; 57 } cf_prp; 58 59 /* .. c:macro:: CF_MAXBLOCK 60 * The maximum block cipher blocksize we support, in bytes. 61 */ 62 #define CF_MAXBLOCK 16 63 64 #endif 65