core.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /*
  2. * Argon2 reference source code package - reference C implementations
  3. *
  4. * Copyright 2015
  5. * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
  6. *
  7. * You may use this work under the terms of a Creative Commons CC0 1.0
  8. * License/Waiver or the Apache Public License 2.0, at your option. The terms of
  9. * these licenses can be found at:
  10. *
  11. * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
  12. * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * You should have received a copy of both of these licenses along with this
  15. * software. If not, they may be obtained at the above URLs.
  16. */
  17. /*For memory wiping*/
  18. #ifdef _MSC_VER
  19. #include <windows.h>
  20. #include <winbase.h> /* For SecureZeroMemory */
  21. #endif
  22. #if defined __STDC_LIB_EXT1__
  23. #define __STDC_WANT_LIB_EXT1__ 1
  24. #endif
  25. #define VC_GE_2005(version) (version >= 1400)
  26. /* for explicit_bzero() on glibc */
  27. #define _DEFAULT_SOURCE
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include "core.h"
  32. #include "thread.h"
  33. #include "blake2/blake2.h"
  34. #include "blake2/blake2-impl.h"
  35. #ifdef GENKAT
  36. #include "genkat.h"
  37. #endif
  38. #if defined(__clang__)
  39. #if __has_attribute(optnone)
  40. #define NOT_OPTIMIZED __attribute__((optnone))
  41. #endif
  42. #elif defined(__GNUC__)
  43. #define GCC_VERSION \
  44. (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
  45. #if GCC_VERSION >= 40400
  46. #define NOT_OPTIMIZED __attribute__((optimize("O0")))
  47. #endif
  48. #endif
  49. #ifndef NOT_OPTIMIZED
  50. #define NOT_OPTIMIZED
  51. #endif
  52. /***************Instance and Position constructors**********/
  53. void init_block_value(block *b, uint8_t in) { memset(b->v, in, sizeof(b->v)); }
  54. void copy_block(block *dst, const block *src) {
  55. memcpy(dst->v, src->v, sizeof(uint64_t) * ARGON2_QWORDS_IN_BLOCK);
  56. }
  57. void xor_block(block *dst, const block *src) {
  58. int i;
  59. for (i = 0; i < ARGON2_QWORDS_IN_BLOCK; ++i) {
  60. dst->v[i] ^= src->v[i];
  61. }
  62. }
  63. static void load_block(block *dst, const void *input) {
  64. unsigned i;
  65. for (i = 0; i < ARGON2_QWORDS_IN_BLOCK; ++i) {
  66. dst->v[i] = load64((const uint8_t *)input + i * sizeof(dst->v[i]));
  67. }
  68. }
  69. static void store_block(void *output, const block *src) {
  70. unsigned i;
  71. for (i = 0; i < ARGON2_QWORDS_IN_BLOCK; ++i) {
  72. store64((uint8_t *)output + i * sizeof(src->v[i]), src->v[i]);
  73. }
  74. }
  75. /***************Memory functions*****************/
  76. int allocate_memory(const argon2_context_t *context, uint8_t **memory,
  77. size_t num, size_t size) {
  78. size_t memory_size = num*size;
  79. if (memory == NULL) {
  80. return ARGON2_MEMORY_ALLOCATION_ERROR;
  81. }
  82. /* 1. Check for multiplication overflow */
  83. if (size != 0 && memory_size / size != num) {
  84. return ARGON2_MEMORY_ALLOCATION_ERROR;
  85. }
  86. /* 2. Try to allocate with appropriate allocator */
  87. if (context->allocate_cbk) {
  88. (context->allocate_cbk)(memory, memory_size);
  89. } else {
  90. *memory = malloc(memory_size);
  91. }
  92. if (*memory == NULL) {
  93. return ARGON2_MEMORY_ALLOCATION_ERROR;
  94. }
  95. return ARGON2_OK;
  96. }
  97. void free_memory(const argon2_context_t *context, uint8_t *memory,
  98. size_t num, size_t size) {
  99. size_t memory_size = num*size;
  100. clear_internal_memory(memory, memory_size);
  101. if (context->free_cbk) {
  102. (context->free_cbk)(memory, memory_size);
  103. } else {
  104. free(memory);
  105. }
  106. }
  107. #if defined(__OpenBSD__)
  108. #define HAVE_EXPLICIT_BZERO 1
  109. #elif defined(__GLIBC__) && defined(__GLIBC_PREREQ)
  110. #if __GLIBC_PREREQ(2,25)
  111. #define HAVE_EXPLICIT_BZERO 1
  112. #endif
  113. #endif
  114. void NOT_OPTIMIZED secure_wipe_memory(void *v, size_t n) {
  115. #if defined(_MSC_VER) && VC_GE_2005(_MSC_VER)
  116. SecureZeroMemory(v, n);
  117. #elif defined memset_s
  118. memset_s(v, n, 0, n);
  119. #elif defined(HAVE_EXPLICIT_BZERO)
  120. explicit_bzero(v, n);
  121. #else
  122. static void *(*const volatile memset_sec)(void *, int, size_t) = &memset;
  123. memset_sec(v, 0, n);
  124. #endif
  125. }
  126. /* Memory clear flag defaults to true. */
  127. int FLAG_clear_internal_memory = 1;
  128. void clear_internal_memory(void *v, size_t n) {
  129. if (FLAG_clear_internal_memory && v) {
  130. secure_wipe_memory(v, n);
  131. }
  132. }
  133. void finalize(const argon2_context_t *context, argon2_instance_t *instance) {
  134. if (context != NULL && instance != NULL) {
  135. block blockhash;
  136. uint32_t l;
  137. copy_block(&blockhash, instance->memory + instance->lane_length - 1);
  138. /* XOR the last blocks */
  139. for (l = 1; l < instance->lanes; ++l) {
  140. uint32_t last_block_in_lane =
  141. l * instance->lane_length + (instance->lane_length - 1);
  142. xor_block(&blockhash, instance->memory + last_block_in_lane);
  143. }
  144. /* Hash the result */
  145. {
  146. uint8_t blockhash_bytes[ARGON2_BLOCK_SIZE];
  147. store_block(blockhash_bytes, &blockhash);
  148. kp_blake2b_long(context->out, context->outlen, blockhash_bytes,
  149. ARGON2_BLOCK_SIZE);
  150. /* clear blockhash and blockhash_bytes */
  151. clear_internal_memory(blockhash.v, ARGON2_BLOCK_SIZE);
  152. clear_internal_memory(blockhash_bytes, ARGON2_BLOCK_SIZE);
  153. }
  154. #ifdef GENKAT
  155. print_tag(context->out, context->outlen);
  156. #endif
  157. free_memory(context, (uint8_t *)instance->memory,
  158. instance->memory_blocks, sizeof(block));
  159. }
  160. }
  161. uint32_t index_alpha(const argon2_instance_t *instance,
  162. const argon2_position_t *position, uint32_t pseudo_rand,
  163. int same_lane) {
  164. /*
  165. * Pass 0:
  166. * This lane : all already finished segments plus already constructed
  167. * blocks in this segment
  168. * Other lanes : all already finished segments
  169. * Pass 1+:
  170. * This lane : (SYNC_POINTS - 1) last segments plus already constructed
  171. * blocks in this segment
  172. * Other lanes : (SYNC_POINTS - 1) last segments
  173. */
  174. uint32_t reference_area_size;
  175. uint64_t relative_position;
  176. uint32_t start_position, absolute_position;
  177. if (0 == position->pass) {
  178. /* First pass */
  179. if (0 == position->slice) {
  180. /* First slice */
  181. reference_area_size =
  182. position->index - 1; /* all but the previous */
  183. } else {
  184. if (same_lane) {
  185. /* The same lane => add current segment */
  186. reference_area_size =
  187. position->slice * instance->segment_length +
  188. position->index - 1;
  189. } else {
  190. reference_area_size =
  191. position->slice * instance->segment_length +
  192. ((position->index == 0) ? (-1) : 0);
  193. }
  194. }
  195. } else {
  196. /* Second pass */
  197. if (same_lane) {
  198. reference_area_size = instance->lane_length -
  199. instance->segment_length + position->index -
  200. 1;
  201. } else {
  202. reference_area_size = instance->lane_length -
  203. instance->segment_length +
  204. ((position->index == 0) ? (-1) : 0);
  205. }
  206. }
  207. /* 1.2.4. Mapping pseudo_rand to 0..<reference_area_size-1> and produce
  208. * relative position */
  209. relative_position = pseudo_rand;
  210. relative_position = relative_position * relative_position >> 32;
  211. relative_position = reference_area_size - 1 -
  212. (reference_area_size * relative_position >> 32);
  213. /* 1.2.5 Computing starting position */
  214. start_position = 0;
  215. if (0 != position->pass) {
  216. start_position = (position->slice == ARGON2_SYNC_POINTS - 1)
  217. ? 0
  218. : (position->slice + 1) * instance->segment_length;
  219. }
  220. /* 1.2.6. Computing absolute position */
  221. absolute_position = (start_position + relative_position) %
  222. instance->lane_length; /* absolute position */
  223. return absolute_position;
  224. }
  225. /* Single-threaded version for p=1 case */
  226. static int fill_memory_blocks_st(argon2_instance_t *instance) {
  227. uint32_t r, s, l;
  228. for (r = 0; r < instance->passes; ++r) {
  229. for (s = 0; s < ARGON2_SYNC_POINTS; ++s) {
  230. for (l = 0; l < instance->lanes; ++l) {
  231. argon2_position_t position = {r, l, (uint8_t)s, 0};
  232. fill_segment(instance, position);
  233. }
  234. }
  235. #ifdef GENKAT
  236. internal_kat(instance, r); /* Print all memory blocks */
  237. #endif
  238. }
  239. return ARGON2_OK;
  240. }
  241. #if !defined(ARGON2_NO_THREADS)
  242. #ifdef _WIN32
  243. static unsigned __stdcall fill_segment_thr(void *thread_data)
  244. #else
  245. static void *fill_segment_thr(void *thread_data)
  246. #endif
  247. {
  248. argon2_thread_data *my_data = thread_data;
  249. fill_segment(my_data->instance_ptr, my_data->pos);
  250. argon2_thread_exit();
  251. return 0;
  252. }
  253. /* Multi-threaded version for p > 1 case */
  254. static int fill_memory_blocks_mt(argon2_instance_t *instance) {
  255. uint32_t r, s;
  256. argon2_thread_handle_t *thread = NULL;
  257. argon2_thread_data *thr_data = NULL;
  258. int rc = ARGON2_OK;
  259. /* 1. Allocating space for threads */
  260. thread = calloc(instance->lanes, sizeof(argon2_thread_handle_t));
  261. if (thread == NULL) {
  262. rc = ARGON2_MEMORY_ALLOCATION_ERROR;
  263. goto fail;
  264. }
  265. thr_data = calloc(instance->lanes, sizeof(argon2_thread_data));
  266. if (thr_data == NULL) {
  267. rc = ARGON2_MEMORY_ALLOCATION_ERROR;
  268. goto fail;
  269. }
  270. for (r = 0; r < instance->passes; ++r) {
  271. for (s = 0; s < ARGON2_SYNC_POINTS; ++s) {
  272. uint32_t l, ll;
  273. /* 2. Calling threads */
  274. for (l = 0; l < instance->lanes; ++l) {
  275. argon2_position_t position;
  276. /* 2.1 Join a thread if limit is exceeded */
  277. if (l >= instance->threads) {
  278. if (kp_argon2_thread_join(thread[l - instance->threads])) {
  279. rc = ARGON2_THREAD_FAIL;
  280. goto fail;
  281. }
  282. }
  283. /* 2.2 Create thread */
  284. position.pass = r;
  285. position.lane = l;
  286. position.slice = (uint8_t)s;
  287. position.index = 0;
  288. thr_data[l].instance_ptr =
  289. instance; /* preparing the thread input */
  290. memcpy(&(thr_data[l].pos), &position,
  291. sizeof(argon2_position_t));
  292. if (kp_argon2_thread_create(&thread[l], &fill_segment_thr,
  293. (void *)&thr_data[l])) {
  294. /* Wait for already running threads */
  295. for (ll = 0; ll < l; ++ll)
  296. kp_argon2_thread_join(thread[ll]);
  297. rc = ARGON2_THREAD_FAIL;
  298. goto fail;
  299. }
  300. /* fill_segment(instance, position); */
  301. /*Non-thread equivalent of the lines above */
  302. }
  303. /* 3. Joining remaining threads */
  304. for (l = instance->lanes - instance->threads; l < instance->lanes;
  305. ++l) {
  306. if (kp_argon2_thread_join(thread[l])) {
  307. rc = ARGON2_THREAD_FAIL;
  308. goto fail;
  309. }
  310. }
  311. }
  312. #ifdef GENKAT
  313. internal_kat(instance, r); /* Print all memory blocks */
  314. #endif
  315. }
  316. fail:
  317. if (thread != NULL) {
  318. free(thread);
  319. }
  320. if (thr_data != NULL) {
  321. free(thr_data);
  322. }
  323. return rc;
  324. }
  325. #endif /* ARGON2_NO_THREADS */
  326. int fill_memory_blocks(argon2_instance_t *instance) {
  327. if (instance == NULL || instance->lanes == 0) {
  328. return ARGON2_INCORRECT_PARAMETER;
  329. }
  330. #if defined(ARGON2_NO_THREADS)
  331. return fill_memory_blocks_st(instance);
  332. #else
  333. return instance->threads == 1 ?
  334. fill_memory_blocks_st(instance) : fill_memory_blocks_mt(instance);
  335. #endif
  336. }
  337. int validate_inputs(const argon2_context_t *context) {
  338. if (NULL == context) {
  339. return ARGON2_INCORRECT_PARAMETER;
  340. }
  341. if (NULL == context->out) {
  342. return ARGON2_OUTPUT_PTR_NULL;
  343. }
  344. /* Validate output length */
  345. if (ARGON2_MIN_OUTLEN > context->outlen) {
  346. return ARGON2_OUTPUT_TOO_SHORT;
  347. }
  348. if (ARGON2_MAX_OUTLEN < context->outlen) {
  349. return ARGON2_OUTPUT_TOO_LONG;
  350. }
  351. /* Validate password (required param) */
  352. if (NULL == context->pwd) {
  353. if (0 != context->pwdlen) {
  354. return ARGON2_PWD_PTR_MISMATCH;
  355. }
  356. }
  357. if (ARGON2_MIN_PWD_LENGTH > context->pwdlen) {
  358. return ARGON2_PWD_TOO_SHORT;
  359. }
  360. if (ARGON2_MAX_PWD_LENGTH < context->pwdlen) {
  361. return ARGON2_PWD_TOO_LONG;
  362. }
  363. /* Validate salt (required param) */
  364. if (NULL == context->salt) {
  365. if (0 != context->saltlen) {
  366. return ARGON2_SALT_PTR_MISMATCH;
  367. }
  368. }
  369. if (ARGON2_MIN_SALT_LENGTH > context->saltlen) {
  370. return ARGON2_SALT_TOO_SHORT;
  371. }
  372. if (ARGON2_MAX_SALT_LENGTH < context->saltlen) {
  373. return ARGON2_SALT_TOO_LONG;
  374. }
  375. /* Validate secret (optional param) */
  376. if (NULL == context->secret) {
  377. if (0 != context->secretlen) {
  378. return ARGON2_SECRET_PTR_MISMATCH;
  379. }
  380. } else {
  381. if (ARGON2_MIN_SECRET > context->secretlen) {
  382. return ARGON2_SECRET_TOO_SHORT;
  383. }
  384. if (ARGON2_MAX_SECRET < context->secretlen) {
  385. return ARGON2_SECRET_TOO_LONG;
  386. }
  387. }
  388. /* Validate associated data (optional param) */
  389. if (NULL == context->ad) {
  390. if (0 != context->adlen) {
  391. return ARGON2_AD_PTR_MISMATCH;
  392. }
  393. } else {
  394. if (ARGON2_MIN_AD_LENGTH > context->adlen) {
  395. return ARGON2_AD_TOO_SHORT;
  396. }
  397. if (ARGON2_MAX_AD_LENGTH < context->adlen) {
  398. return ARGON2_AD_TOO_LONG;
  399. }
  400. }
  401. /* Validate memory cost */
  402. if (ARGON2_MIN_MEMORY > context->m_cost) {
  403. return ARGON2_MEMORY_TOO_LITTLE;
  404. }
  405. if (ARGON2_MAX_MEMORY < context->m_cost) {
  406. return ARGON2_MEMORY_TOO_MUCH;
  407. }
  408. if (context->m_cost < 8 * context->lanes) {
  409. return ARGON2_MEMORY_TOO_LITTLE;
  410. }
  411. /* Validate time cost */
  412. if (ARGON2_MIN_TIME > context->t_cost) {
  413. return ARGON2_TIME_TOO_SMALL;
  414. }
  415. if (ARGON2_MAX_TIME < context->t_cost) {
  416. return ARGON2_TIME_TOO_LARGE;
  417. }
  418. /* Validate lanes */
  419. if (ARGON2_MIN_LANES > context->lanes) {
  420. return ARGON2_LANES_TOO_FEW;
  421. }
  422. if (ARGON2_MAX_LANES < context->lanes) {
  423. return ARGON2_LANES_TOO_MANY;
  424. }
  425. /* Validate threads */
  426. if (ARGON2_MIN_THREADS > context->threads) {
  427. return ARGON2_THREADS_TOO_FEW;
  428. }
  429. if (ARGON2_MAX_THREADS < context->threads) {
  430. return ARGON2_THREADS_TOO_MANY;
  431. }
  432. if (NULL != context->allocate_cbk && NULL == context->free_cbk) {
  433. return ARGON2_FREE_MEMORY_CBK_NULL;
  434. }
  435. if (NULL == context->allocate_cbk && NULL != context->free_cbk) {
  436. return ARGON2_ALLOCATE_MEMORY_CBK_NULL;
  437. }
  438. return ARGON2_OK;
  439. }
  440. void fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance) {
  441. uint32_t l;
  442. /* Make the first and second block in each lane as G(H0||0||i) or
  443. G(H0||1||i) */
  444. uint8_t blockhash_bytes[ARGON2_BLOCK_SIZE];
  445. for (l = 0; l < instance->lanes; ++l) {
  446. store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, 0);
  447. store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH + 4, l);
  448. kp_blake2b_long(blockhash_bytes, ARGON2_BLOCK_SIZE, blockhash,
  449. ARGON2_PREHASH_SEED_LENGTH);
  450. load_block(&instance->memory[l * instance->lane_length + 0],
  451. blockhash_bytes);
  452. store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, 1);
  453. kp_blake2b_long(blockhash_bytes, ARGON2_BLOCK_SIZE, blockhash,
  454. ARGON2_PREHASH_SEED_LENGTH);
  455. load_block(&instance->memory[l * instance->lane_length + 1],
  456. blockhash_bytes);
  457. }
  458. clear_internal_memory(blockhash_bytes, ARGON2_BLOCK_SIZE);
  459. }
  460. void initial_hash(uint8_t *blockhash, argon2_context_t *context,
  461. argon2_type_t type) {
  462. blake2b_state BlakeHash;
  463. uint8_t value[sizeof(uint32_t)];
  464. if (NULL == context || NULL == blockhash) {
  465. return;
  466. }
  467. kp_blake2b_init(&BlakeHash, ARGON2_PREHASH_DIGEST_LENGTH);
  468. store32(&value, context->lanes);
  469. kp_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value));
  470. store32(&value, context->outlen);
  471. kp_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value));
  472. store32(&value, context->m_cost);
  473. kp_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value));
  474. store32(&value, context->t_cost);
  475. kp_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value));
  476. store32(&value, context->version);
  477. kp_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value));
  478. store32(&value, (uint32_t)type);
  479. kp_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value));
  480. store32(&value, context->pwdlen);
  481. kp_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value));
  482. if (context->pwd != NULL) {
  483. kp_blake2b_update(&BlakeHash, (const uint8_t *)context->pwd,
  484. context->pwdlen);
  485. if (context->flags & ARGON2_FLAG_CLEAR_PASSWORD) {
  486. secure_wipe_memory(context->pwd, context->pwdlen);
  487. context->pwdlen = 0;
  488. }
  489. }
  490. store32(&value, context->saltlen);
  491. kp_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value));
  492. if (context->salt != NULL) {
  493. kp_blake2b_update(&BlakeHash, (const uint8_t *)context->salt,
  494. context->saltlen);
  495. }
  496. store32(&value, context->secretlen);
  497. kp_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value));
  498. if (context->secret != NULL) {
  499. kp_blake2b_update(&BlakeHash, (const uint8_t *)context->secret,
  500. context->secretlen);
  501. if (context->flags & ARGON2_FLAG_CLEAR_SECRET) {
  502. secure_wipe_memory(context->secret, context->secretlen);
  503. context->secretlen = 0;
  504. }
  505. }
  506. store32(&value, context->adlen);
  507. kp_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value));
  508. if (context->ad != NULL) {
  509. kp_blake2b_update(&BlakeHash, (const uint8_t *)context->ad,
  510. context->adlen);
  511. }
  512. kp_blake2b_final(&BlakeHash, blockhash, ARGON2_PREHASH_DIGEST_LENGTH);
  513. }
  514. int initialize(argon2_instance_t *instance, argon2_context_t *context) {
  515. uint8_t blockhash[ARGON2_PREHASH_SEED_LENGTH];
  516. int result = ARGON2_OK;
  517. if (instance == NULL || context == NULL)
  518. return ARGON2_INCORRECT_PARAMETER;
  519. instance->context_ptr = context;
  520. /* 1. Memory allocation */
  521. result = allocate_memory(context, (uint8_t **)&(instance->memory),
  522. instance->memory_blocks, sizeof(block));
  523. if (result != ARGON2_OK) {
  524. return result;
  525. }
  526. /* 2. Initial hashing */
  527. /* H_0 + 8 extra bytes to produce the first blocks */
  528. /* uint8_t blockhash[ARGON2_PREHASH_SEED_LENGTH]; */
  529. /* Hashing all inputs */
  530. initial_hash(blockhash, context, instance->type);
  531. /* Zeroing 8 extra bytes */
  532. clear_internal_memory(blockhash + ARGON2_PREHASH_DIGEST_LENGTH,
  533. ARGON2_PREHASH_SEED_LENGTH -
  534. ARGON2_PREHASH_DIGEST_LENGTH);
  535. #ifdef GENKAT
  536. initial_kat(blockhash, context, instance->type);
  537. #endif
  538. /* 3. Creating first blocks, we always have at least two blocks in a slice
  539. */
  540. fill_first_blocks(blockhash, instance);
  541. /* Clearing the hash */
  542. clear_internal_memory(blockhash, ARGON2_PREHASH_SEED_LENGTH);
  543. return ARGON2_OK;
  544. }