units: store what sort of units a variable is in
[smatch.git] / smatch_hash.c
blob9885c8bf08dc952f31ce476ea0fd57bff36aca9f
1 /*
2 * Copyright (C) 2022 Oracle.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
18 #include <string.h>
19 #include <openssl/evp.h>
21 #define MTAG_ALIAS_BIT (1ULL << 63)
23 unsigned long long str_to_llu_hash_helper(const char *str)
25 unsigned char c[EVP_MAX_MD_SIZE];
26 unsigned long long *tag = (unsigned long long *)&c;
27 EVP_MD_CTX *mdctx;
28 const EVP_MD *md;
29 int len;
31 len = strlen(str);
33 mdctx = EVP_MD_CTX_create();
34 md = EVP_sha1();
36 EVP_DigestInit_ex(mdctx, md, NULL);
37 EVP_DigestUpdate(mdctx, str, len);
38 EVP_DigestFinal_ex(mdctx, c, NULL);
39 EVP_MD_CTX_destroy(mdctx);
41 /* I don't like negatives in the DB */
42 *tag &= ~MTAG_ALIAS_BIT;
44 return *tag;