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