VirtualBox

Changeset 102292 in vbox


Ignore:
Timestamp:
Nov 24, 2023 1:01:41 PM (16 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
160426
Message:

IPRT: Implemented SHA-crypt 256 / 512 variants, along with testcases. Needed for password hashing in cloud-init-based Linux installers [build fix, moved docs]. bugref:10551

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/crypto/shacrypt.h

    r102289 r102292  
    5252RT_C_DECLS_BEGIN
    5353
    54 RTDECL(int) RTShaCrypt256(const char *pszKey, const char *pszSalt, uint32_t cRounds, uint8_t pabHash[RTSHA256_HASH_SIZE]);
    55 RTDECL(int) RTShaCrypt256ToString(uint8_t abHash[RTSHA256_HASH_SIZE], const char *pszSalt, uint32_t cRounds, char *pszString, size_t cbString);
    56 RTDECL(int) RTShaCrypt512(const char *pszKey, const char *szSalt, uint32_t cRounds, uint8_t pabHash[RTSHA512_HASH_SIZE]);
    57 RTDECL(int) RTShaCrypt512ToString(uint8_t abHash[RTSHA512_HASH_SIZE], const char *pszSalt, uint32_t cRounds, char *pszString, size_t cbString);
     54/**
     55 * Calculates a SHAcrypt (SHA-256) digest.
     56 *
     57 * @returns VBox status code.
     58 * @param   pszKey              Key (password) to use.
     59 * @param   pszSalt             Salt to use.
     60 *                              Must be >= RT_SHACRYPT_MIN_SALT_LEN and <= RT_SHACRYPT_MAX_SALT_LEN.
     61 * @param   cRounds             Number of rounds to use.
     62 * @param   pabHash             Where to return the hash on success.
     63 *
     64 * @note    This implements SHA-crypt.txt Version: 0.6 2016-8-31.
     65 */
     66RTR3DECL(int) RTShaCrypt256(const char *pszKey, const char *pszSalt, uint32_t cRounds, uint8_t pabHash[RTSHA256_HASH_SIZE]);
     67
     68/**
     69 * Returns a SHAcrypt (SHA-256) digest as a printable scheme.
     70 *
     71 * @returns VBox status code.
     72 * @param   pabHash             SHAcrypt (SHA-256) digest to return printable scheme for.
     73 * @param   pszSalt             Salt to use. Must match the salt used when generating \a pabHash via RTSha256Crypt().
     74 * @param   cRounds             Number of rounds used for generating \a pabHash.
     75 * @param   pszString           Where to store the printable string on success.
     76 * @param   cbString            Size (in bytes) of \a pszString.
     77 *
     78 * @note    This implements step 22 of SHA-crypt.txt Version: 0.6 2016-8-31.
     79 */
     80RTR3DECL(int) RTShaCrypt256ToString(uint8_t abHash[RTSHA256_HASH_SIZE], const char *pszSalt, uint32_t cRounds, char *pszString, size_t cbString);
     81
     82
     83/**
     84 * Calculates a SHAcrypt (SHA-512) digest.
     85 *
     86 * @returns VBox status code.
     87 * @param   pszKey              Key (password) to use.
     88 * @param   pszSalt             Salt to use.
     89 *                              Must be >= RT_SHACRYPT_MIN_SALT_LEN and <= RT_SHACRYPT_MAX_SALT_LEN.
     90 * @param   cRounds             Number of rounds to use.
     91 * @param   pabHash             Where to return the hash on success.
     92 *
     93 * @note    This implements SHA-crypt.txt Version: 0.6 2016-8-31.
     94 */
     95RTR3DECL(int) RTShaCrypt512(const char *pszKey, const char *szSalt, uint32_t cRounds, uint8_t pabHash[RTSHA512_HASH_SIZE]);
     96
     97
     98/**
     99 * Returns a SHAcrypt (SHA-512) digest as a printable scheme.
     100 *
     101 * @returns VBox status code.
     102 * @param   pabHash             SHAcrypt (SHA-512) digest to return printable scheme for.
     103 * @param   pszSalt             Salt to use. Must match the salt used when generating \a pabHash via RTSha512Crypt().
     104 * @param   cRounds             Number of rounds used for generating \a pabHash.
     105 * @param   pszString           Where to store the printable string on success.
     106 * @param   cbString            Size (in bytes) of \a pszString.
     107 *
     108 * @note    This implements step 22 of SHA-crypt.txt Version: 0.6 2016-8-31.
     109 */
     110RTR3DECL(int) RTShaCrypt512ToString(uint8_t abHash[RTSHA512_HASH_SIZE], const char *pszSalt, uint32_t cRounds, char *pszString, size_t cbString);
    58111
    59112RT_C_DECLS_END
  • trunk/src/VBox/Runtime/common/crypto/shacrypt.cpp

    r102289 r102292  
    4747
    4848
    49 /**
    50  * Calculates a SHAcrypt (SHA-256) digest.
    51  *
    52  * @returns VBox status code.
    53  * @param   pszKey              Key (password) to use.
    54  * @param   pszSalt             Salt to use.
    55  *                              Must be >= RT_SHACRYPT_MIN_SALT_LEN and <= RT_SHACRYPT_MAX_SALT_LEN.
    56  * @param   cRounds             Number of rounds to use.
    57  * @param   pabHash             Where to return the hash on success.
    58  *
    59  * @note    This implements SHA-crypt.txt Version: 0.6 2016-8-31.
    60  */
    61 int RTShaCrypt256(const char *pszKey, const char *pszSalt, uint32_t cRounds, uint8_t pabHash[RTSHA256_HASH_SIZE])
     49
     50RTR3DECL(int) RTShaCrypt256(const char *pszKey, const char *pszSalt, uint32_t cRounds, uint8_t pabHash[RTSHA256_HASH_SIZE])
    6251{
    6352    AssertPtrReturn(pszKey,   VERR_INVALID_POINTER);
     
    182171}
    183172
    184 /**
    185  * Returns a SHAcrypt (SHA-256) digest as a printable scheme.
    186  *
    187  * @returns VBox status code.
    188  * @param   pabHash             SHAcrypt (SHA-256) digest to return printable scheme for.
    189  * @param   pszSalt             Salt to use. Must match the salt used when generating \a pabHash via RTSha256Crypt().
    190  * @param   cRounds             Number of rounds used for generating \a pabHash.
    191  * @param   pszString           Where to store the printable string on success.
    192  * @param   cbString            Size (in bytes) of \a pszString.
    193  *
    194  * @note    This implements step 22 of SHA-crypt.txt Version: 0.6 2016-8-31.
    195  */
    196 int RTShaCrypt256ToString(uint8_t abHash[RTSHA256_HASH_SIZE], const char *pszSalt, uint32_t cRounds,
    197                           char *pszString, size_t cbString)
     173
     174RTR3DECL(int) RTShaCrypt256ToString(uint8_t abHash[RTSHA256_HASH_SIZE], const char *pszSalt, uint32_t cRounds,
     175                                    char *pszString, size_t cbString)
    198176{
    199177    AssertPtrReturn(pszSalt,   VERR_INVALID_POINTER);
     
    243221}
    244222
    245 /**
    246  * Calculates a SHAcrypt (SHA-512) digest.
    247  *
    248  * @returns VBox status code.
    249  * @param   pszKey              Key (password) to use.
    250  * @param   pszSalt             Salt to use.
    251  *                              Must be >= RT_SHACRYPT_MIN_SALT_LEN and <= RT_SHACRYPT_MAX_SALT_LEN.
    252  * @param   cRounds             Number of rounds to use.
    253  * @param   pabHash             Where to return the hash on success.
    254  *
    255  * @note    This implements SHA-crypt.txt Version: 0.6 2016-8-31.
    256  */
    257 int RTShaCrypt512(const char *pszKey, const char *pszSalt, uint32_t cRounds, uint8_t pabHash[RTSHA512_HASH_SIZE])
     223
     224RTR3DECL(int) RTShaCrypt512(const char *pszKey, const char *pszSalt, uint32_t cRounds, uint8_t pabHash[RTSHA512_HASH_SIZE])
    258225{
    259226    AssertPtrReturn(pszKey,   VERR_INVALID_POINTER);
     
    378345}
    379346
    380 /**
    381  * Returns a SHAcrypt (SHA-512) digest as a printable scheme.
    382  *
    383  * @returns VBox status code.
    384  * @param   pabHash             SHAcrypt (SHA-512) digest to return printable scheme for.
    385  * @param   pszSalt             Salt to use. Must match the salt used when generating \a pabHash via RTSha512Crypt().
    386  * @param   cRounds             Number of rounds used for generating \a pabHash.
    387  * @param   pszString           Where to store the printable string on success.
    388  * @param   cbString            Size (in bytes) of \a pszString.
    389  *
    390  * @note    This implements step 22 of SHA-crypt.txt Version: 0.6 2016-8-31.
    391  */
    392 int RTShaCrypt512ToString(uint8_t abHash[RTSHA512_HASH_SIZE], const char *pszSalt, uint32_t cRounds,
    393                           char *pszString, size_t cbString)
     347
     348RTR3DECL(int) RTShaCrypt512ToString(uint8_t abHash[RTSHA512_HASH_SIZE], const char *pszSalt, uint32_t cRounds,
     349                                    char *pszString, size_t cbString)
    394350{
    395351    AssertPtrReturn(pszSalt,   VERR_INVALID_POINTER);
Note: See TracChangeset for help on using the changeset viewer.

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