VirtualBox

Ignore:
Timestamp:
Nov 24, 2023 1:01:41 PM (17 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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