cyclic.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * ZMap Copyright 2013 Regents of the University of Michigan
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy
  6. * of the License at http://www.apache.org/licenses/LICENSE-2.0
  7. */
  8. #ifndef CYCLIC_H
  9. #define CYCLIC_H
  10. #include <stdint.h>
  11. #include <stddef.h>
  12. #include "aesrand.h"
  13. // Represents a multiplicative cyclic group (Z/pZ)*
  14. typedef struct cyclic_group {
  15. uint64_t prime; // p
  16. uint64_t known_primroot; // Known primitive root of (Z/pZ)*
  17. size_t num_prime_factors; // Length of num_prime_factors
  18. uint64_t prime_factors[10]; // Unique prime factors of (p-1)
  19. } cyclic_group_t;
  20. // Represents a cycle in a group
  21. typedef struct cycle {
  22. const cyclic_group_t* group;
  23. uint64_t generator;
  24. uint32_t offset;
  25. } cycle_t;
  26. // Get a cyclic_group_t of at least min_size.
  27. // Pointer into static data, do not free().
  28. const cyclic_group_t* get_group(uint64_t min_size);
  29. // Generate cycle (find generator and inverse)
  30. cycle_t make_cycle(const cyclic_group_t* group, aesrand_t *aes);
  31. // Perform the isomorphism from (Z/pZ)+ to (Z/pZ)*
  32. // Given known primitive root of (Z/pZ)* n, with x in (Z/pZ)+, do:
  33. // f(x) = n^x mod p
  34. //
  35. // The isomorphism in the reverse direction is discrete log, and is
  36. // therefore hard.
  37. uint64_t isomorphism(uint64_t additive_elt, const cyclic_group_t* mult_group);
  38. #endif