crypto1.c 600 B

12345678910111213141516171819202122
  1. #pragma GCC optimize("O3")
  2. #pragma GCC optimize("-funroll-all-loops")
  3. #include <inttypes.h>
  4. #include "crypto1.h"
  5. #include "mfkey.h"
  6. #define BIT(x, n) ((x) >> (n) & 1)
  7. void crypto1_get_lfsr(struct Crypto1State* state, MfClassicKey* lfsr) {
  8. int i;
  9. uint64_t lfsr_value = 0;
  10. for(i = 23; i >= 0; --i) {
  11. lfsr_value = lfsr_value << 1 | BIT(state->odd, i ^ 3);
  12. lfsr_value = lfsr_value << 1 | BIT(state->even, i ^ 3);
  13. }
  14. // Assign the key value to the MfClassicKey struct
  15. for(i = 0; i < 6; ++i) {
  16. lfsr->data[i] = (lfsr_value >> ((5 - i) * 8)) & 0xFF;
  17. }
  18. }