void scrypt(const uint8_t *password, size_t password_len, const uint8_t *salt, size_t salt_len, uint8_t Nfactor, uint8_t rfactor, uint8_t pfactor, uint8_t *out, size_t bytes) { scrypt_aligned_alloc YX, V; uint8_t *X, *Y; uint32_t N, r, p, chunk_bytes, i; #if !defined(SCRYPT_CHOOSE_COMPILETIME) scrypt_ROMixfn scrypt_ROMix = scrypt_getROMix(); #endif #if !defined(SCRYPT_TEST) static int power_on_self_test = 0; if (!power_on_self_test) { power_on_self_test = 1; if (!scrypt_power_on_self_test()) scrypt_fatal_error("scrypt: power on self test failed"); } #endif if (Nfactor > scrypt_maxN) scrypt_fatal_error("scrypt: N out of range"); if (rfactor > scrypt_maxr) scrypt_fatal_error("scrypt: r out of range"); if (pfactor > scrypt_maxp) scrypt_fatal_error("scrypt: p out of range"); N = (1 << (Nfactor + 1)); r = (1 << rfactor); p = (1 << pfactor); chunk_bytes = SCRYPT_BLOCK_BYTES * r * 2; V = scrypt_alloc((uint64_t)N * chunk_bytes); YX = scrypt_alloc((p + 1) * chunk_bytes); //printf("%d-%d-%d\n" ,N,r,p); //printf("%d\n", chunk_bytes); //printf("%d\n", (uint64_t)N * chunk_bytes); /* 1: X = PBKDF2(password, salt) */ Y = YX.ptr; X = Y + chunk_bytes; scrypt_pbkdf2(password, password_len, salt, salt_len, 1, X, chunk_bytes * p); /* 2: X = ROMix(X) */ for (i = 0; i < p; i++) scrypt_ROMix((scrypt_mix_word_t *)(X + (chunk_bytes * i)), (scrypt_mix_word_t *)Y, (scrypt_mix_word_t *)V.ptr, N, r); /* 3: Out = PBKDF2(password, X) */ scrypt_pbkdf2(password, password_len, X, chunk_bytes * p, 1, out, bytes); scrypt_ensure_zero(YX.ptr, (p + 1) * chunk_bytes); scrypt_free(&V); scrypt_free(&YX); }
void scrypt(const uint8_t *password, size_t password_len, const uint8_t *salt, size_t salt_len, uint32_t N, uint8_t *out, size_t bytes, uint8_t *X, uint8_t *Y, uint8_t *V, uint32_t r, uint32_t p) { uint32_t chunk_bytes, i; chunk_bytes = SCRYPT_BLOCK_BYTES * r * 2; scrypt_pbkdf2(password, password_len, salt, salt_len, 1, X, chunk_bytes * p); /* 2: X = ROMix(X) */ for (i = 0; i < p; i++) scrypt_ROMix((scrypt_mix_word_t *)(X + (chunk_bytes * i)), (scrypt_mix_word_t *)Y, (scrypt_mix_word_t *)V, N, r); /* 3: Out = PBKDF2(password, X) */ scrypt_pbkdf2(password, password_len, X, chunk_bytes * p, 1, out, bytes); #ifdef SCRYPT_PREVENT_STATE_LEAK scrypt_ensure_zero(YX.ptr, (p + 1) * chunk_bytes); #endif }
void my_scrypt(const uint8_t *password, size_t password_len, const uint8_t *salt, size_t salt_len, uint8_t *out) { scrypt_aligned_alloc YX, V; uint8_t *X, *Y; #if !defined(SCRYPT_CHOOSE_COMPILETIME) scrypt_ROMixfn scrypt_ROMix = scrypt_getROMix(); #endif /* #if !defined(SCRYPT_TEST) static int power_on_self_test = 0; if (!power_on_self_test) { power_on_self_test = 1; if (!scrypt_power_on_self_test()) scrypt_fatal_error("scrypt: power on self test failed"); } #endif */ V = scrypt_alloc((uint64_t)512 * chunk_bytes); YX = scrypt_alloc(2 * chunk_bytes); /* 1: X = PBKDF2(password, salt) */ Y = YX.ptr; X = Y + chunk_bytes; scrypt_pbkdf2(password, password_len, salt, salt_len, 1, X, chunk_bytes); /* 2: X = ROMix(X) */ scrypt_ROMix((scrypt_mix_word_t *)X, (scrypt_mix_word_t *)Y, (scrypt_mix_word_t *)V.ptr, 512, 1); /* 3: Out = PBKDF2(password, X) */ scrypt_pbkdf2(password, password_len, X, chunk_bytes, 1, out, 32); scrypt_ensure_zero(YX.ptr, 2 * chunk_bytes); scrypt_free(&V); scrypt_free(&YX); }