1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef CTR_H 6 #define CTR_H 1 7 8 #include "blapii.h" 9 10 /* This structure is defined in this header because both ctr.c and gcm.c 11 * need it. */ 12 struct CTRContextStr { 13 freeblCipherFunc cipher; 14 void *context; 15 unsigned char counter[MAX_BLOCK_SIZE]; 16 unsigned char buffer[MAX_BLOCK_SIZE]; 17 unsigned char counterFirst[MAX_BLOCK_SIZE]; /* counter overlfow value */ 18 PRBool checkWrap; /*check for counter overflow*/ 19 unsigned long counterBits; 20 unsigned int bufPtr; 21 }; 22 23 typedef struct CTRContextStr CTRContext; 24 25 SECStatus CTR_InitContext(CTRContext *ctr, void *context, 26 freeblCipherFunc cipher, const unsigned char *param); CTR_InitContext(CTRContext * ctr,void * context,freeblCipherFunc cipher,const unsigned char * param)27 28 /* 29 * The context argument is the inner cipher context to use with cipher. The 30 * CTRContext does not own context. context needs to remain valid for as long 31 * as the CTRContext is valid. 32 * 33 * The cipher argument is a block cipher in the ECB encrypt mode. 34 */ 35 CTRContext *CTR_CreateContext(void *context, freeblCipherFunc cipher, 36 const unsigned char *param); 37 38 void CTR_DestroyContext(CTRContext *ctr, PRBool freeit); 39 40 SECStatus CTR_Update(CTRContext *ctr, unsigned char *outbuf, 41 unsigned int *outlen, unsigned int maxout, 42 const unsigned char *inbuf, unsigned int inlen, 43 unsigned int blocksize); 44 45 #ifdef USE_HW_AES 46 SECStatus CTR_Update_HW_AES(CTRContext *ctr, unsigned char *outbuf, 47 unsigned int *outlen, unsigned int maxout, 48 const unsigned char *inbuf, unsigned int inlen, 49 unsigned int blocksize); 50 #endif 51 52 #endif 53