VirtualBox

Changeset 102292 in vbox for trunk/include


Ignore:
Timestamp:
Nov 24, 2023 1:01:41 PM (14 months ago)
Author:
vboxsync
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/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
Note: See TracChangeset for help on using the changeset viewer.

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