simaka_crypto.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2009 Martin Willi
  3. * HSR Hochschule fuer Technik Rapperswil
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. * for more details.
  14. */
  15. /**
  16. * @defgroup simaka_crypto simaka_crypto
  17. * @{ @ingroup libsimaka
  18. */
  19. #ifndef SIMAKA_CRYPTO_H_
  20. #define SIMAKA_CRYPTO_H_
  21. #include <library.h>
  22. typedef struct simaka_crypto_t simaka_crypto_t;
  23. /**
  24. * EAP-SIM/AKA crypto helper and key derivation class.
  25. */
  26. struct simaka_crypto_t {
  27. /**
  28. * Get the signer to use for AT_MAC calculation/verification.
  29. *
  30. * @return signer reference, NULL if no keys have been derived
  31. */
  32. signer_t* (*get_signer)(simaka_crypto_t *this);
  33. /**
  34. * Get the signer to use for AT_ENCR_DATA encryption/decryption.
  35. *
  36. * @return crypter reference, NULL if no keys have been derived
  37. */
  38. crypter_t* (*get_crypter)(simaka_crypto_t *this);
  39. /**
  40. * Get the random number generator.
  41. *
  42. * @return rng reference
  43. */
  44. rng_t* (*get_rng)(simaka_crypto_t *this);
  45. /**
  46. * Derive keys after full authentication.
  47. *
  48. * This methods derives the k_encr/k_auth keys and loads them into the
  49. * internal crypter/signer instances. The passed data is method specific:
  50. * For EAP-SIM, it is "n*Kc|NONCE_MT|Version List|Selected Version", for
  51. * EAP-AKA it is "IK|CK".
  52. *
  53. * @param id peer identity
  54. * @param data method specific data
  55. * @param mk chunk receiving allocated master key MK
  56. * @param msk chunk receiving allocated MSK
  57. * @return TRUE if keys allocated and derived successfully
  58. */
  59. bool (*derive_keys_full)(simaka_crypto_t *this, identification_t *id,
  60. chunk_t data, chunk_t *mk, chunk_t *msk);
  61. /**
  62. * Derive k_encr/k_auth keys from MK using fast reauthentication.
  63. *
  64. * This methods derives the k_encr/k_auth keys and loads them into the
  65. * internal crypter/signer instances.
  66. *
  67. * @param mk master key
  68. * @return TRUE if keys derived successfully
  69. */
  70. bool (*derive_keys_reauth)(simaka_crypto_t *this, chunk_t mk);
  71. /**
  72. * Derive MSK using fast reauthentication.
  73. *
  74. * @param id fast reauthentication identity
  75. * @param counter fast reauthentication counter value, network order
  76. * @param nonce_s server generated NONCE_S value
  77. * @param mk master key of last full authentication
  78. * @param msk chunk receiving allocated MSK
  79. * @return TRUE if MSK allocated and derived successfully
  80. */
  81. bool (*derive_keys_reauth_msk)(simaka_crypto_t *this,
  82. identification_t *id, chunk_t counter,
  83. chunk_t nonce_s, chunk_t mk, chunk_t *msk);
  84. /**
  85. * Clear keys (partially) derived.
  86. */
  87. void (*clear_keys)(simaka_crypto_t *this);
  88. /**
  89. * Destroy a simaka_crypto_t.
  90. */
  91. void (*destroy)(simaka_crypto_t *this);
  92. };
  93. /**
  94. * Create a simaka_crypto instance.
  95. *
  96. * @return EAP-SIM/AKA crypto instance, NULL if algorithms missing
  97. */
  98. simaka_crypto_t *simaka_crypto_create();
  99. #endif /** SIMAKA_CRYPTO_H_ @}*/