suricata
util-crypt.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2012 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Roliers Jean-Paul <popof.fpn@gmail.co>
22  *
23  * Implements cryptographic functions.
24  * Based on the libtomcrypt library ( http://libtom.org/?page=features&newsitems=5&whatfile=crypt )
25  */
26 
27 #ifndef UTIL_CRYPT_H_
28 #define UTIL_CRYPT_H_
29 
30 #include "suricata-common.h"
31 
32 typedef enum {
36 
40 
41 } CryptId;
42 
43 #ifndef HAVE_NSS
44 
45 #define SHA1_LENGTH 20
46 
47 #define LOAD32H(x, y) \
48  { x = ((unsigned long)((y)[0] & 255)<<24) | \
49  ((unsigned long)((y)[1] & 255)<<16) | \
50  ((unsigned long)((y)[2] & 255)<<8) | \
51  ((unsigned long)((y)[3] & 255)); }
52 
53 #define STORE64H(x, y) \
54  { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
55  (y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255); \
56  (y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \
57  (y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); }
58 
59 #define STORE32H(x, y) \
60  { (y)[0] = (unsigned char)(((x)>>24)&255); (y)[1] = (unsigned char)(((x)>>16)&255); \
61  (y)[2] = (unsigned char)(((x)>>8)&255); (y)[3] = (unsigned char)((x)&255); }
62 
63 #define ROL(x, y) ( (((unsigned long)(x)<<(unsigned long)((y)&31)) | (((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
64 #define ROLc(x, y) ( (((unsigned long)(x)<<(unsigned long)((y)&31)) | (((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
65 #ifndef MIN
66 #define MIN(x, y) ( ((x)<(y))?(x):(y) )
67 #endif
68 
69 typedef struct Sha1State_ {
70  uint64_t length;
71  uint32_t state[5], curlen;
72  unsigned char buf[64];
73 } Sha1State;
74 
75 typedef union HashState_ {
76  char dummy[1];
78  void *data;
79 } HashState;
80 
81 #endif /* don't HAVE_NSS */
82 
83 int ComputeSHA1(const uint8_t * inbuf, size_t inbuf_len,
84  uint8_t *outbuf, size_t outbuf_len);
85 int Base64Encode(const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen);
86 
87 #endif /* UTIL_CRYPT_H_ */
uint64_t length
Definition: util-crypt.h:70
Sha1State sha1
Definition: util-crypt.h:77
uint32_t state[5]
Definition: util-crypt.h:71
uint32_t curlen
Definition: util-crypt.h:71
unsigned char buf[64]
Definition: util-crypt.h:72
int Base64Encode(const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen)
Definition: util-crypt.c:272
struct Sha1State_ Sha1State
CryptId
Definition: util-crypt.h:32
int ComputeSHA1(const uint8_t *inbuf, size_t inbuf_len, uint8_t *outbuf, size_t outbuf_len)
calculate SHA1 hash
Definition: util-crypt.c:230
void * data
Definition: util-crypt.h:78
union HashState_ HashState