crypto.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. #include <stdint.h>
  3. #include <switch.h>
  4. #include "nx/nca.h"
  5. typedef enum
  6. {
  7. EncryptMode_Decrypt = 0x0,
  8. EncryptMode_Encrypt = 0x1
  9. } EncryptMode;
  10. extern uint8_t HEADER_KEK[0x10];
  11. extern uint8_t HEADER_KEY[0x20];
  12. extern uint8_t HEADER_KEY_0[0x10];
  13. extern uint8_t HEADER_KEY_1[0x10];
  14. //
  15. bool init_crypto(void);
  16. void exit_crypto(void);
  17. //
  18. uint32_t crypto_get_sys_key_gen(void);
  19. uint32_t crypto_get_highest_key_gen(NcaKeyAreaEncryptionKeyIndex index);
  20. bool crypto_has_key_gen(NcaKeyAreaEncryptionKeyIndex index, uint32_t key_gen);
  21. bool crypto_has_key_gen_from_keys(NcaKeyAreaEncryptionKeyIndex index, uint8_t key_gen);
  22. const uint8_t *crypto_get_keak_from_keys(NcaKeyAreaEncryptionKeyIndex index, uint8_t key_gen);
  23. const uint8_t *crypto_get_titlekek_from_keys(uint8_t key_gen);
  24. //
  25. const uint8_t *crypto_return_keak_source(NcaKeyAreaEncryptionKeyIndex index);
  26. void *crypto_aes(const void *in, void *out, const uint8_t *key, EncryptMode mode);
  27. void *crypto_aes_ctr(const void *in, void *out, const uint8_t *key, uint8_t *counter, size_t size, uint64_t offset);
  28. void *crypto_aes_cbc(const void *in, void *out, const uint8_t *key, size_t size, void *iv, EncryptMode mode);
  29. void *crypto_aes_xts(const void *in, void *out, const uint8_t *key0, const uint8_t *key1, uint64_t sector, size_t sector_size, size_t data_size, EncryptMode mode);