Debian Codegraph @

src/OVAL/probes/SEAP/sexp-ID.c

raw symbols SCIP
1 /**
2 * @file sexp-ID.c
3 * @brief S-expression object ID functions - implementation
4 * @author "Daniel Kopecek" <[email protected]>
5 *
6 * @addtogroup SEXPRESSIONS
7 * @{
8 */
9
10 /*
11 * Copyright 2011 Red Hat Inc., Durham, North Carolina.
12 * All Rights Reserved.
13 *
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 *
28 * Authors:
29 * Daniel Kopecek <[email protected]>
30 */
31
32 #ifdef HAVE_CONFIG_H
33 #include <config.h>
34 #endif
35
36 #include <stdio.h>
37 #include <string.h>
38 #include <stdint.h>
39 #include <stdbool.h>
40 #include <errno.h>
41
42 #include "_sexp-types.h"
43 #include "_sexp-value.h"
44 #include "_sexp-rawptr.h"
45 #include "_sexp-ID.h"
46
47 #include "MurmurHash3.h"
48
49 static SEXP_ID_t SEXP_ID_hash(void *buf, size_t len, SEXP_ID_t seed, int part)
50 {
51 uint64_t resbuf[2];
52
53 if (part != 0 && part != 1) {
54 return -1;
55 }
56
57 MurmurHash3_x86_128(buf, (int)len, (uint32_t)((0x7C0FFEE7 ^ seed) ^ (seed >> 32)), resbuf);
58
59 return (resbuf[part]);
60 }
61
62 static int SEXP_ID_v_callback(const SEXP_t *sexp, __IDres_pair *pair)
63 {
64 SEXP_val_t v_dsc;
65
66 if (sexp == NULL || pair == NULL) {
67 return -1;
68 }
69
70 /*
71 * Fill v_dsc with metainformation
72 */
73 SEXP_val_dsc(&v_dsc, sexp->s_valp);
74
75 switch (v_dsc.type) {
76 case SEXP_VALTYPE_NUMBER:
77 case SEXP_VALTYPE_STRING:
78 pair->hash = SEXP_ID_hash(v_dsc.mem, v_dsc.hdr->size, pair->hash, pair->part);
79 break;
80 case SEXP_VALTYPE_LIST:
81 {
82 SEXP_rawval_lblk_cb ((uintptr_t)SEXP_LCASTP(v_dsc.mem)->b_addr,
83 (int (*)(SEXP_t *, void *)) SEXP_ID_v_callback,
84 (void *) pair,
85 SEXP_LCASTP(v_dsc.mem)->offset + 1);
86
87 pair->hash = SEXP_ID_hash(&pair->hash, 1,
88 pair->hash + SEXP_LCASTP(v_dsc.mem)->offset, pair->part);
89 break;
90 }
91 case SEXP_VALTYPE_EMPTY:
92 pair->hash = SEXP_ID_hash(&pair->hash, 1, pair->hash, pair->part);
93 break;
94 default:
95 /* Unknown S-exp value type */
96 abort ();
97 }
98
99 return (0);
100 }
101
102 SEXP_ID_t SEXP_ID_v(const SEXP_t *s)
103 {
104 __IDres_pair pair;
105
106 pair.hash = 0xAD30917100C0FFEE;
107 pair.part = 0;
108
109 SEXP_ID_v_callback(s, &pair);
110
111 return (pair.hash);
112 }
113
114 /// @}