Lattice base Key-Exchange algorithm (quantum resistant cryptography)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.2KB

  1. // +build linux !freebsd !cgo
  2. /* this file implements the RNG,
  3. please don't use OS based RNG and don't use RDSEED , processor based RNG generator
  4. The current function is just a placeholder and must be replaced before this code goes into production
  5. TAGS are used so as this file is not used, and should be replaced
  6. Any attempt to cross-compile would cause this file to be skipped and thus the RND gen fixed
  7. */
  8. package rlwe
  9. import "time"
  10. import "crypto/rand"
  11. var x uint64 /* The state must be seeded with a nonzero value. */
  12. func init(){
  13. x = uint64(time.Now().UTC().UnixNano()) // asumming we only 20 bits of entry, since time can be guessed
  14. z:= x % 1024
  15. z += 41
  16. buf := make([]byte, z)
  17. _, err := rand.Read(buf)
  18. if err != nil {
  19. panic("error: initialing RNG generator")
  20. return
  21. }
  22. for i := uint64(0); i < z ; i++{
  23. x ^= x >> buf[i]&63 // a
  24. x ^= x << 25 // b
  25. x ^= x >> buf[i]&63 // c
  26. xorshift64star()
  27. }
  28. // now lets mix in os rnd generator for time being
  29. }
  30. func xorshift64star() uint64 {
  31. x ^= x >> 12 // a
  32. x ^= x << 25 // b
  33. x ^= x >> 27 // c
  34. return x * uint64(2685821657736338717)
  35. }
  36. /* this function generates a uint64 RNG */
  37. func Random_Safe_uint64() uint64 {
  38. return xorshift64star()
  39. }