bcrypt.h
Go to the documentation of this file.
1 /**
2  * @file bcrypt.h
3  * @brief bcrypt password hashing function
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCrypto Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 1.9.6
29  **/
30 
31 #ifndef _BCRYPT_H
32 #define _BCRYPT_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "cipher/blowfish.h"
37 
38 //Minimum acceptable value for cost parameter
39 #ifndef BCRYPT_MIN_COST
40  #define BCRYPT_MIN_COST 3
41 #elif (BCRYPT_MIN_COST < 3)
42  #error BCRYPT_MIN_COST parameter is not valid
43 #endif
44 
45 //Maximum acceptable value for cost parameter
46 #ifndef BCRYPT_MAX_COST
47  #define BCRYPT_MAX_COST 31
48 #elif (BCRYPT_MAX_COST < BCRYPT_MIN_COST || BCRYPT_MAX_COST > 31)
49  #error BCRYPT_MAX_COST parameter is not valid
50 #endif
51 
52 //Length of bcrypt hash string
53 #define BCRYPT_HASH_STRING_LEN 60
54 
55 //C++ guard
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
60 //bcrypt related functions
61 error_t bcryptHashPassword(const PrngAlgo *prngAlgo, void *prngContext,
62  uint_t cost, const char_t *password, char_t *hash, size_t *hashLen);
63 
64 error_t bcryptVerifyPassword(const char_t *password, const char_t *hash);
65 
66 error_t bcrypt(uint_t cost, const uint8_t *salt, const char_t *password,
67  char_t *hash, size_t *hashLen);
68 
70  const uint8_t *salt, size_t saltLen, const char_t *password,
71  size_t passwordLen);
72 
73 //C++ guard
74 #ifdef __cplusplus
75 }
76 #endif
77 
78 #endif
Common interface for pseudo-random number generators.
Definition: crypto.h:1168
error_t eksBlowfishSetup(BlowfishContext *context, uint_t cost, const uint8_t *salt, size_t saltLen, const char_t *password, size_t passwordLen)
Expensive key setup.
Definition: bcrypt.c:243
error_t bcryptVerifyPassword(const char_t *password, const char_t *hash)
Password verification function.
Definition: bcrypt.c:90
error_t bcrypt(uint_t cost, const uint8_t *salt, const char_t *password, char_t *hash, size_t *hashLen)
bcrypt algorithm
Definition: bcrypt.c:158
error_t
Error codes.
Definition: error.h:42
error_t bcryptHashPassword(const PrngAlgo *prngAlgo, void *prngContext, uint_t cost, const char_t *password, char_t *hash, size_t *hashLen)
Password hashing function.
Definition: bcrypt.c:55
General definitions for cryptographic algorithms.
Blowfish encryption algorithm.
uint8_t hash
Definition: tls.h:1369
char char_t
Definition: compiler_port.h:43
Blowfish algorithm context.
Definition: blowfish.h:52
unsigned int uint_t
Definition: compiler_port.h:45