Index: src/scrypt.h ================================================================== --- src/scrypt.h +++ src/scrypt.h @@ -27,13 +27,13 @@ /** @file */ @class OFHMAC; /** - * @brief The parameters for @ref of_scrypt. + * @brief The parameters for @ref OFScrypt. */ -typedef struct of_scrypt_parameters_t { +typedef struct OFScryptParameters { /** @brief The block size to use. */ size_t blockSize; /** @brief The CPU/memory cost factor to use. */ size_t costFactor; /** @brief The parallelization to use. */ @@ -54,27 +54,27 @@ * @ref key needs to have enough storage. */ size_t keyLength; /** @brief Whether data may be stored in swappable memory. */ bool allowsSwappableMemory; -} of_scrypt_parameters_t; +} OFScryptParameters; #ifdef __cplusplus extern "C" { #endif -extern void of_salsa20_8_core(uint32_t buffer[_Nonnull 16]); -extern void of_scrypt_block_mix(uint32_t *output, const uint32_t *input, +extern void OFSalsa20_8Core(uint32_t buffer[_Nonnull 16]); +extern void OFScryptBlockMix(uint32_t *output, const uint32_t *input, size_t blockSize); -extern void of_scrypt_romix(uint32_t *buffer, size_t blockSize, +extern void OFScryptROMix(uint32_t *buffer, size_t blockSize, size_t costFactor, uint32_t *tmp); /** * @brief Derives a key from a password and a salt using scrypt. * * @param param The parameters to use */ -extern void of_scrypt(of_scrypt_parameters_t param); +extern void OFScrypt(OFScryptParameters param); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END Index: src/scrypt.m ================================================================== --- src/scrypt.m +++ src/scrypt.m @@ -25,11 +25,11 @@ #import "scrypt.h" #import "pbkdf2.h" void -of_salsa20_8_core(uint32_t buffer[16]) +OFSalsa20_8Core(uint32_t buffer[16]) { uint32_t tmp[16]; for (uint_fast8_t i = 0; i < 16; i++) tmp[i] = OF_BSWAP32_IF_BE(buffer[i]); @@ -75,15 +75,15 @@ of_explicit_memset(tmp, 0, sizeof(tmp)); } void -of_scrypt_block_mix(uint32_t *output, const uint32_t *input, size_t blockSize) +OFScryptBlockMix(uint32_t *output, const uint32_t *input, size_t blockSize) { uint32_t tmp[16]; - /* Check defined here and executed in of_scrypt() */ + /* Check defined here and executed in OFScrypt() */ #define OVERFLOW_CHECK_1 \ if (param.blockSize > SIZE_MAX / 2 || \ 2 * param.blockSize - 1 > SIZE_MAX / 16) \ @throw [OFOutOfRangeException exception]; @@ -91,11 +91,11 @@ for (size_t i = 0; i < 2 * blockSize; i++) { for (size_t j = 0; j < 16; j++) tmp[j] ^= input[i * 16 + j]; - of_salsa20_8_core(tmp); + OFSalsa20_8Core(tmp); /* * Even indices are stored in the first half and odd ones in * the second. */ @@ -104,14 +104,14 @@ of_explicit_memset(tmp, 0, sizeof(tmp)); } void -of_scrypt_romix(uint32_t *buffer, size_t blockSize, size_t costFactor, +OFScryptROMix(uint32_t *buffer, size_t blockSize, size_t costFactor, uint32_t *tmp) { - /* Check defined here and executed in of_scrypt() */ + /* Check defined here and executed in OFScrypt() */ #define OVERFLOW_CHECK_2 \ if (param.blockSize > SIZE_MAX / 128 / param.costFactor) \ @throw [OFOutOfRangeException exception]; uint32_t *tmp2 = tmp + 32 * blockSize; @@ -118,29 +118,29 @@ memcpy(tmp, buffer, 128 * blockSize); for (size_t i = 0; i < costFactor; i++) { memcpy(tmp2 + i * 32 * blockSize, tmp, 128 * blockSize); - of_scrypt_block_mix(tmp, tmp2 + i * 32 * blockSize, blockSize); + OFScryptBlockMix(tmp, tmp2 + i * 32 * blockSize, blockSize); } for (size_t i = 0; i < costFactor; i++) { uint32_t j = OF_BSWAP32_IF_BE(tmp[(2 * blockSize - 1) * 16]) & (costFactor - 1); for (size_t k = 0; k < 32 * blockSize; k++) tmp[k] ^= tmp2[j * 32 * blockSize + k]; - of_scrypt_block_mix(buffer, tmp, blockSize); + OFScryptBlockMix(buffer, tmp, blockSize); if (i < costFactor - 1) memcpy(tmp, buffer, 128 * blockSize); } } void -of_scrypt(of_scrypt_parameters_t param) +OFScrypt(OFScryptParameters param) { OFSecureData *tmp = nil, *buffer = nil; OFHMAC *HMAC = nil; if (param.blockSize == 0 || param.costFactor <= 1 || @@ -194,11 +194,11 @@ param.blockSize, .allowsSwappableMemory = param.allowsSwappableMemory }); for (size_t i = 0; i < param.parallelization; i++) - of_scrypt_romix(bufferItems + i * 32 * param.blockSize, + OFScryptROMix(bufferItems + i * 32 * param.blockSize, param.blockSize, param.costFactor, tmpItems); OFPBKDF2((OFPBKDF2Parameters){ .HMAC = HMAC, .iterations = 1, Index: tests/ScryptTests.m ================================================================== --- tests/ScryptTests.m +++ tests/ScryptTests.m @@ -139,24 +139,24 @@ uint32_t ROMixBuffer[32], ROMixTmp[17 * 32]; unsigned char output[64]; TEST(@"Salsa20/8 Core", R(memcpy(salsa20Buffer, salsa20Input, 64)) && - R(of_salsa20_8_core(salsa20Buffer)) && + R(OFSalsa20_8Core(salsa20Buffer)) && memcmp(salsa20Buffer, salsa20Output, 64) == 0) TEST(@"Block mix", - R(of_scrypt_block_mix(blockMixBuffer, blockMixInput.u32, 1)) && + R(OFScryptBlockMix(blockMixBuffer, blockMixInput.u32, 1)) && memcmp(blockMixBuffer, blockMixOutput, 128) == 0) TEST(@"ROMix", R(memcpy(ROMixBuffer, ROMixInput, 128)) && - R(of_scrypt_romix(ROMixBuffer, 1, 16, ROMixTmp)) && + R(OFScryptROMix(ROMixBuffer, 1, 16, ROMixTmp)) && memcmp(ROMixBuffer, ROMixOutput, 128) == 0) TEST(@"scrypt test vector #1", - R(of_scrypt((of_scrypt_parameters_t){ + R(OFScrypt((OFScryptParameters){ .blockSize = 1, .costFactor = 16, .parallelization = 1, .salt = (unsigned char *)"", .saltLength = 0, @@ -166,11 +166,11 @@ .keyLength = 64, .allowsSwappableMemory = true })) && memcmp(output, testVector1, 64) == 0) TEST(@"scrypt test vector #2", - R(of_scrypt((of_scrypt_parameters_t){ + R(OFScrypt((OFScryptParameters){ .blockSize = 8, .costFactor = 1024, .parallelization = 16, .salt = (unsigned char *)"NaCl", .saltLength = 4, @@ -180,11 +180,11 @@ .keyLength = 64, .allowsSwappableMemory = true })) && memcmp(output, testVector2, 64) == 0) TEST(@"scrypt test vector #3", - R(of_scrypt((of_scrypt_parameters_t){ + R(OFScrypt((OFScryptParameters){ .blockSize = 8, .costFactor = 16384, .parallelization = 1, .salt = (unsigned char *)"SodiumChloride", .saltLength = 14, @@ -196,11 +196,11 @@ })) && memcmp(output, testVector3, 64) == 0) /* The forth test vector is too expensive to include it in the tests. */ #if 0 TEST(@"scrypt test vector #4", - R(of_scrypt((of_scrypt_parameters_t){ + R(OFScrypt((OFScryptParameters){ .blockSize = 8, .costFactor = 1048576, .parallelization = 1, .salt = (unsigned char *)"SodiumChloride", .saltLength = 14,