Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

31 rinda
894 B

  1. #include "chacha.h"
  2. //#include "params.h"
  3. #include "prg.h"
  4. const unsigned char zero_nonce[12] = {0};
  5. /**
  6. * Generates rlen output bytes using ChaCha20 with a zero nonce and counter = 0
  7. */
  8. void prg(unsigned char *r, unsigned long long rlen, const unsigned char *key, uint key_len)
  9. {
  10. CRYPTO_chacha_20_keystream(r, rlen, key, zero_nonce, 0);
  11. }
  12. /**
  13. * Generates rlen output bytes using ChaCha20.
  14. * Nonce and counter are set depending on the address addr.
  15. */
  16. void prg_with_counter(unsigned char *r, unsigned long long rlen, const unsigned char *key, uint key_len, const unsigned char addr[16])
  17. {
  18. int i;
  19. unsigned char nonce[12];
  20. for(i = 0; i < 12; i++)
  21. {
  22. nonce[i] = addr[i];
  23. }
  24. uint32_t counter;
  25. counter = (addr[12] << 24)|(addr[13] << 16)|(addr[14] << 8)|addr[15];
  26. // TODO: Check address handling. Endianess?
  27. CRYPTO_chacha_20_keystream(r, rlen, key, nonce, counter);
  28. }