suricata
datasets-sha256.c
Go to the documentation of this file.
1 /* Copyright (C) 2017-2019 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 Victor Julien <victor@inliniac.net>
22  */
23 
24 #include "suricata-common.h"
25 #include "conf.h"
26 #include "datasets.h"
27 #include "datasets-sha256.h"
28 #include "util-thash.h"
29 #include "util-print.h"
30 #include "util-crypt.h" // encode base64
31 #include "util-base64.h" // decode base64
32 
33 int Sha256StrSet(void *dst, void *src)
34 {
35  Sha256Type *src_s = src;
36  Sha256Type *dst_s = dst;
37  memcpy(dst_s->sha256, src_s->sha256, sizeof(dst_s->sha256));
38  dst_s->rep = src_s->rep;
39  return 0;
40 }
41 
42 bool Sha256StrCompare(void *a, void *b)
43 {
44  Sha256Type *as = a;
45  Sha256Type *bs = b;
46 
47  return (memcmp(as->sha256, bs->sha256, sizeof(as->sha256)) == 0);
48 }
49 
50 uint32_t Sha256StrHash(void *s)
51 {
52  Sha256Type *str = s;
53  uint32_t hash = 5381;
54 
55  for (int i = 0; i < (int)sizeof(str->sha256); i++) {
56  hash = ((hash << 5) + hash) + str->sha256[i]; /* hash * 33 + c */
57  }
58  return hash;
59 }
60 
61 // data stays in hash
62 void Sha256StrFree(void *s)
63 {
64  // no dynamic data
65 }
int Sha256StrSet(void *dst, void *src)
uint8_t sha256[32]
uint16_t src
DataRepType rep
#define str(s)
uint16_t dst
void Sha256StrFree(void *s)
uint32_t Sha256StrHash(void *s)
bool Sha256StrCompare(void *a, void *b)