-
Notifications
You must be signed in to change notification settings - Fork 2
/
hash.h
81 lines (72 loc) · 2.77 KB
/
hash.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
+----------------------------------------------------------------------+
| hash.h: hashing functions include (hashing library for IBM DB2) |
+----------------------------------------------------------------------+
| Copyright (c) 2007-2018 Helmut K. C. Tessarek |
+----------------------------------------------------------------------+
| Licensed under the Apache License, Version 2.0 (the "License"); you |
| may not use this file except in compliance with the License. You may |
| obtain a copy of the License at |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| implied. See the License for the specific language governing |
| permissions and limitations under the License. |
+----------------------------------------------------------------------+
| Author: Helmut K. C. Tessarek |
+----------------------------------------------------------------------+
| Website: http://tessus.github.io/db2-hash-routines |
+----------------------------------------------------------------------+
*/
#ifndef HASH_H
#define HASH_H
#include "apr.h"
#include "apr_md5.h"
#include "apr_sha1.h"
#include "apr_strings.h"
#include "apu_version.h"
#include <time.h>
#if APR_HAVE_CRYPT_H
#include <crypt.h>
#endif
#if APR_HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if APR_HAVE_STRING_H
#include <string.h>
#endif
#if APR_HAVE_UNISTD_H
#include <unistd.h>
#endif
#if APU_MAJOR_VERSION == 1 && APU_MINOR_VERSION >= 5
#define BCRYPT_ALGO_SUPPORTED 1
#else
#define BCRYPT_ALGO_SUPPORTED 0
#endif
#define ALG_CRYPT 1
#define ALG_PHPMD5 2
#define ALG_APMD5 3
#define ALG_APSHA 4
#define ALG_SHA256 5
#define ALG_SHA512 6
#define ALG_APSHA256 7
#define ALG_BCRYPT 8
#define ALG_SHA256HEX 9
#define ALG_SHA1HEX 10
#define APR_SHA256PW_ID "{SHA256}"
#define APR_SHA256PW_IDLEN 8
#ifndef FALSE // FALSE
#define FALSE 0
#endif
#ifndef TRUE // TRUE
#define TRUE (!FALSE)
#endif
static int generate_salt(char *s, size_t size);
int is_valid_salt(const char *salt);
int supported(int alg);
void sha256_base64(const char *clear, int len, char *out);
char* mk_hash(int alg, const char *passwd, const char *mysalt);
int validate_hash(const char *password, const char *hash);
#endif