VirtualBox

source: vbox/trunk/include/iprt/crypto/shacrypt.h@ 102297

Last change on this file since 102297 was 102297, checked in by vboxsync, 15 months ago

IPRT/crypto/shacrypt: Better string length checks for RTCrShaCryptXXXToString(). bugref:10551

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1/** @file
2 * IPRT - Crypto - SHA-crypt.
3 */
4
5/*
6 * Copyright (C) 2023 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef IPRT_INCLUDED_crypto_shacrypt_h
37#define IPRT_INCLUDED_crypto_shacrypt_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <iprt/sha.h>
43
44
45RT_C_DECLS_BEGIN
46
47/** @defgroup grp_rt_crshacrypt RTCrShaCrypt - SHAcrypt functions
48 * @ingroup grp_rt
49 * @{
50 */
51
52/** Default number of rounds for SHA-crypt 256/512. */
53#define RT_SHACRYPT_DEFAULT_ROUNDS 5000
54/** Minimum salt length (in bytes) for SHA-crypt 256/512. */
55#define RT_SHACRYPT_MIN_SALT_LEN 8
56/** Maximum salt length (in bytes) for SHA-crypt 256/512. */
57#define RT_SHACRYPT_MAX_SALT_LEN 16
58
59
60/**
61 * Calculates a SHAcrypt (SHA-256) digest.
62 *
63 * @returns VBox status code.
64 * @param pszKey Key (password) to use.
65 * @param pszSalt Salt to use.
66 * Must be >= RT_SHACRYPT_MIN_SALT_LEN and <= RT_SHACRYPT_MAX_SALT_LEN.
67 * @param cRounds Number of rounds to use.
68 * @param abHash Where to return the hash on success.
69 *
70 * @note This implements SHA-crypt.txt Version: 0.6 2016-8-31.
71 */
72RTR3DECL(int) RTCrShaCrypt256(const char *pszKey, const char *pszSalt, uint32_t cRounds, uint8_t abHash[RTSHA256_HASH_SIZE]);
73
74
75/**
76 * Returns a SHAcrypt (SHA-256) digest as a printable scheme.
77 *
78 * @returns VBox status code.
79 * @param abHash SHAcrypt (SHA-256) digest to return printable scheme for.
80 * @param pszSalt Salt to use. Must match the salt used when generating \a pabHash via RTSha256Crypt().
81 * @param cRounds Number of rounds used for generating \a pabHash.
82 * @param pszString Where to store the printable string on success.
83 * @param cchString Size of \a pszString.
84 * Should be at least RTSHA256_DIGEST_LEN + 1 bytes.
85 *
86 * @note This implements step 22 of SHA-crypt.txt Version: 0.6 2016-8-31.
87 */
88RTR3DECL(int) RTCrShaCrypt256ToString(uint8_t abHash[RTSHA256_HASH_SIZE], const char *pszSalt, uint32_t cRounds, char *pszString, size_t cchString);
89
90
91/**
92 * Calculates a SHAcrypt (SHA-512) digest.
93 *
94 * @returns VBox status code.
95 * @param pszKey Key (password) to use.
96 * @param pszSalt Salt to use.
97 * Must be >= RT_SHACRYPT_MIN_SALT_LEN and <= RT_SHACRYPT_MAX_SALT_LEN.
98 * @param cRounds Number of rounds to use.
99 * @param abHash Where to return the hash on success.
100 *
101 * @note This implements SHA-crypt.txt Version: 0.6 2016-8-31.
102 */
103RTR3DECL(int) RTCrShaCrypt512(const char *pszKey, const char *pszSalt, uint32_t cRounds, uint8_t abHash[RTSHA512_HASH_SIZE]);
104
105
106/**
107 * Returns a SHAcrypt (SHA-512) digest as a printable scheme.
108 *
109 * @returns VBox status code.
110 * @param abHash SHAcrypt (SHA-512) digest to return printable scheme for.
111 * @param pszSalt Salt to use. Must match the salt used when generating \a pabHash via RTSha512Crypt().
112 * @param cRounds Number of rounds used for generating \a pabHash.
113 * @param pszString Where to store the printable string on success.
114 * @param cchString Size of \a pszString.
115 * Should be at least RTSHA512_DIGEST_LEN + 1 bytes.
116 *
117 * @note This implements step 22 of SHA-crypt.txt Version: 0.6 2016-8-31.
118 */
119RTR3DECL(int) RTCrShaCrypt512ToString(uint8_t abHash[RTSHA512_HASH_SIZE], const char *pszSalt, uint32_t cRounds, char *pszString, size_t cchString);
120
121/** @} */
122
123RT_C_DECLS_END
124
125#endif /* !IPRT_INCLUDED_crypto_shacrypt_h */
126
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette