5f1bb8a41f15ddffedfb6e5abc66097a1dc20f7f
[trex.git] /
1 /*-
2  * Copyright 2009 Colin Percival
3  * Copyright 2013 Alexander Peslyak
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * This file was originally written by Colin Percival as part of the Tarsnap
28  * online backup system.
29  */
30 #ifndef crypto_scrypt_H
31 #define crypto_scrypt_H
32
33 #include <stdint.h>
34
35 #define crypto_pwhash_scryptsalsa208sha256_STRPREFIXBYTES 14
36 #define crypto_pwhash_scryptsalsa208sha256_STRSETTINGBYTES 57
37 #define crypto_pwhash_scryptsalsa208sha256_STRSALTBYTES 32
38 #define crypto_pwhash_scryptsalsa208sha256_STRSALTBYTES_ENCODED 43
39 #define crypto_pwhash_scryptsalsa208sha256_STRHASHBYTES 32
40 #define crypto_pwhash_scryptsalsa208sha256_STRHASHBYTES_ENCODED 43
41
42 #define BYTES2CHARS(bytes) ((((bytes) * 8) + 5) / 6)
43
44 typedef struct {
45         void * base, * aligned;
46         size_t size;
47 } escrypt_region_t;
48
49 typedef escrypt_region_t escrypt_local_t;
50
51 extern int escrypt_init_local(escrypt_local_t * __local);
52
53 extern int escrypt_free_local(escrypt_local_t * __local);
54
55 extern void *alloc_region(escrypt_region_t * region, size_t size);
56 extern int free_region(escrypt_region_t * region);
57
58 typedef int (*escrypt_kdf_t)(escrypt_local_t * __local,
59                              const uint8_t * __passwd, size_t __passwdlen,
60                              const uint8_t * __salt, size_t __saltlen,
61                              uint64_t __N, uint32_t __r, uint32_t __p,
62                              uint8_t * __buf, size_t __buflen);
63
64 extern int escrypt_kdf_nosse(escrypt_local_t * __local,
65     const uint8_t * __passwd, size_t __passwdlen,
66     const uint8_t * __salt, size_t __saltlen,
67     uint64_t __N, uint32_t __r, uint32_t __p,
68     uint8_t * __buf, size_t __buflen);
69
70 extern int escrypt_kdf_sse(escrypt_local_t * __local,
71     const uint8_t * __passwd, size_t __passwdlen,
72     const uint8_t * __salt, size_t __saltlen,
73     uint64_t __N, uint32_t __r, uint32_t __p,
74     uint8_t * __buf, size_t __buflen);
75
76 extern uint8_t * escrypt_r(escrypt_local_t * __local,
77     const uint8_t * __passwd, size_t __passwdlen,
78     const uint8_t * __setting,
79     uint8_t * __buf, size_t __buflen);
80
81 extern uint8_t * escrypt_gensalt_r(
82     uint32_t __N_log2, uint32_t __r, uint32_t __p,
83     const uint8_t * __src, size_t __srclen,
84     uint8_t * __buf, size_t __buflen);
85
86 #endif /* !_CRYPTO_SCRYPT_H_ */