suricata
datasets-sha256.c
Go to the documentation of this file.
1 /* Copyright (C) 2017-2024 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-context-json.h"
28 #include "datasets-sha256.h"
29 #include "util-hash-lookup3.h"
30 #include "util-thash.h"
31 
32 int Sha256StrSet(void *dst, void *src)
33 {
34  Sha256Type *src_s = src;
35  Sha256Type *dst_s = dst;
36  memcpy(dst_s->sha256, src_s->sha256, sizeof(dst_s->sha256));
37  dst_s->rep = src_s->rep;
38  return 0;
39 }
40 
41 int Sha256StrJsonSet(void *dst, void *src)
42 {
43  if (Sha256StrSet(dst, src) < 0)
44  return -1;
45 
46  Sha256Type *src_s = src;
47  Sha256Type *dst_s = dst;
48 
49  if (DatajsonCopyJson(&dst_s->json, &src_s->json) < 0)
50  return -1;
51 
52  return 0;
53 }
54 
55 bool Sha256StrCompare(void *a, void *b)
56 {
57  Sha256Type *as = a;
58  Sha256Type *bs = b;
59 
60  return (memcmp(as->sha256, bs->sha256, sizeof(as->sha256)) == 0);
61 }
62 
63 uint32_t Sha256StrHash(uint32_t hash_seed, void *s)
64 {
65  Sha256Type *str = s;
66  return hashword((uint32_t *)str->sha256, sizeof(str->sha256) / 4, hash_seed);
67 }
68 
69 // data stays in hash
70 void Sha256StrFree(void *s)
71 {
72  // no dynamic data
73 }
74 
75 void Sha256StrJsonFree(void *s)
76 {
77  const Sha256Type *as = s;
78  if (as->json.value) {
79  SCFree(as->json.value);
80  }
81 }
82 
83 uint32_t Sha256StrJsonGetLength(void *s)
84 {
85  const Sha256Type *as = s;
86  return as->json.len;
87 }
Sha256StrJsonSet
int Sha256StrJsonSet(void *dst, void *src)
Definition: datasets-sha256.c:41
DataJsonType::len
uint16_t len
Definition: datasets-context-json.h:34
hashword
uint32_t hashword(const uint32_t *k, size_t length, uint32_t initval)
Definition: util-hash-lookup3.c:172
datasets-sha256.h
Sha256Type::sha256
uint8_t sha256[32]
Definition: datasets-sha256.h:31
Sha256Type::rep
DataRepType rep
Definition: datasets-sha256.h:33
datasets.h
Sha256StrSet
int Sha256StrSet(void *dst, void *src)
Definition: datasets-sha256.c:32
Sha256Type::json
DataJsonType json
Definition: datasets-sha256.h:34
conf.h
Sha256StrJsonGetLength
uint32_t Sha256StrJsonGetLength(void *s)
Definition: datasets-sha256.c:83
Sha256Type
Definition: datasets-sha256.h:30
Sha256StrFree
void Sha256StrFree(void *s)
Definition: datasets-sha256.c:70
Sha256StrJsonFree
void Sha256StrJsonFree(void *s)
Definition: datasets-sha256.c:75
suricata-common.h
datasets-context-json.h
util-hash-lookup3.h
DatajsonCopyJson
int DatajsonCopyJson(DataJsonType *dst, DataJsonType *src)
Definition: datasets-context-json.c:54
str
#define str(s)
Definition: suricata-common.h:308
SCFree
#define SCFree(p)
Definition: util-mem.h:61
Sha256StrCompare
bool Sha256StrCompare(void *a, void *b)
Definition: datasets-sha256.c:55
src
uint16_t src
Definition: app-layer-dnp3.h:5
DataJsonType::value
char * value
Definition: datasets-context-json.h:33
dst
uint16_t dst
Definition: app-layer-dnp3.h:4
util-thash.h
Sha256StrHash
uint32_t Sha256StrHash(uint32_t hash_seed, void *s)
Definition: datasets-sha256.c:63