tsip_milenage.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * Copyright (C) 2010-2011 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. /**@file tsip_milenage.h
  23. * @brief 3GPP authentication and key agreement functions f1, f1*, f2, f3, f4, f5 and f5*.
  24. *
  25. * @section DESCRIPTION
  26. *
  27. * @sa 3G Security
  28. * <a href="http://www.3gpp.org/ftp/Specs/html-info/35205.htm"> 3GPP TS 35.205 </a>
  29. * <a href="http://www.3gpp.org/ftp/Specs/html-info/35206.htm"> 3GPP TS 35.206 </a>
  30. * <a href="http://www.3gpp.org/ftp/Specs/html-info/35207.htm"> 3GPP TS 35.207 </a>
  31. * <a href="http://www.3gpp.org/ftp/Specs/html-info/35208.htm"> 3GPP TS 35.208 </a>
  32. * <a href="http://www.3gpp.org/ftp/Specs/html-info/35909.htm"> 3GPP TS 35.909 </a>
  33. *-------------------------------------------------------------------
  34. * Example algorithms f1, f1*, f2, f3, f4, f5, f5*
  35. *-------------------------------------------------------------------
  36. *
  37. * A sample implementation of the example 3GPP authentication and
  38. * key agreement functions f1, f1*, f2, f3, f4, f5 and f5*. This is
  39. * a byte-oriented implementation of the functions, and of the block
  40. * cipher kernel function Rijndael.
  41. *
  42. * This has been coded for clarity, not necessarily for efficiency.
  43. *
  44. * The functions f2, f3, f4 and f5 share the same inputs and have
  45. * been coded together as a single function. f1, f1* and f5* are
  46. * all coded separately.
  47. *
  48. *-----------------------------------------------------------------
  49. *
  50. * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
  51. *
  52. */
  53. #ifndef TINYSIP_AUTHENTICATION_MILENAGE_H
  54. #define TINYSIP_AUTHENTICATION_MILENAGE_H
  55. #include "tinysip_config.h"
  56. /**@def AKA_AK_SIZE
  57. * a 48-bit anonymity key that is the output of either of the functions f5 and f5*.
  58. * Defined in 3GPP TS 35.206 subclause 2.3.
  59. */
  60. TSIP_BEGIN_DECLS
  61. #define AKA_AK_SIZE 6
  62. typedef uint8_t AKA_AK_T[AKA_AK_SIZE + 1];
  63. /**@def AKA_AMF_SIZE
  64. * 16-bit authentication management field that is an input to the functions f1 and f1*.
  65. * Defined in 3GPP TS 35.206 subclause 2.3.
  66. */
  67. #define AKA_AMF_SIZE 2
  68. typedef uint8_t AKA_AMF_T[AKA_AMF_SIZE + 1];
  69. /**@def AKA_CK_SIZE
  70. * a 128-bit confidentiality key that is the output of the function f3.
  71. * Defined in 3GPP TS 35.206 subclause 2.3.
  72. */
  73. #define AKA_CK_SIZE 16
  74. typedef uint8_t AKA_CK_T[AKA_CK_SIZE + 1];
  75. /**@def AKA_IK_SIZE
  76. * a 128-bit integrity key that is the output of the function f4.
  77. * Defined in 3GPP TS 35.206 subclause 2.3.
  78. */
  79. #define AKA_IK_SIZE 16
  80. typedef uint8_t AKA_IK_T[AKA_IK_SIZE + 1];
  81. /**@def AKA_K_SIZE
  82. * a 128-bit subscriber key that is an input to the functions f1, f1*, f2, f3, f4, f5 and f5*.
  83. * Defined in 3GPP TS 35.206 subclause 2.3.
  84. */
  85. #define AKA_K_SIZE 16
  86. typedef uint8_t AKA_K_T[AKA_K_SIZE + 1];
  87. /**@def AKA_MAC_A_SIZE
  88. * a 64-bit network authentication code that is the output of the function f1.
  89. * Defined in 3GPP TS 35.206 subclause 2.3.
  90. */
  91. #define AKA_MAC_A_SIZE 8
  92. typedef uint8_t AKA_MAC_A_T[AKA_MAC_A_SIZE + 1];
  93. /**@def AKA_MAC_S_SIZE
  94. * a 64-bit network authentication code that is the output of the function f1*.
  95. * Defined in 3GPP TS 35.206 subclause 2.3.
  96. */
  97. #define AKA_MAC_S_SIZE 8
  98. typedef uint8_t AKA_MAC_S_T[AKA_MAC_S_SIZE + 1];
  99. /**@def AKA_OP_SIZE
  100. * a 128-bit Operator Variant Algorithm Configuration Field that is a component of the functions f1, f1*, f2, f3, f4, f5 and f5*.
  101. * Defined in 3GPP TS 35.206 subclause 2.3.
  102. */
  103. #define AKA_OP_SIZE 16
  104. typedef uint8_t AKA_OP_T[AKA_OP_SIZE + 1];
  105. /**@def AKA_OPC_SIZE
  106. * a 128-bit value derived from OP and K and used within the computation of the functions.
  107. * Defined in 3GPP TS 35.206 subclause 2.3.
  108. */
  109. #define AKA_OPC_SIZE 16
  110. typedef uint8_t AKA_OPC_T[AKA_OPC_SIZE + 1];
  111. /**@def AKA_RAND_SIZE
  112. * a 128-bit random challenge that is an input to the functions f1, f1*, f2, f3, f4, f5 and f5*.
  113. * Defined in 3GPP TS 35.206 subclause 2.3.
  114. */
  115. #define AKA_RAND_SIZE 16
  116. typedef uint8_t AKA_RAND_T[AKA_RAND_SIZE + 1];
  117. /**@def AKA_RES_SIZE
  118. * a 64-bit signed response that is the output of the function f2.
  119. * Defined in 3GPP TS 35.206 subclause 2.3.
  120. */
  121. #define AKA_RES_SIZE 8
  122. typedef uint8_t AKA_RES_T[AKA_RES_SIZE + 1];
  123. /**@def AKA_SQN_SIZE
  124. * a 48-bit sequence number that is an input to either of the functions f1 and f1*. (For f1* this input is more precisely called SQNMS.)
  125. * Defined in 3GPP TS 35.206 subclause 2.3.
  126. */
  127. #define AKA_SQN_SIZE 6
  128. typedef uint8_t AKA_SQN_T[AKA_SQN_SIZE + 1];
  129. /**@def AKA_TEMP_SIZE
  130. * a 128-bit value used within the computation of the functions.
  131. * Defined in 3GPP TS 35.206 subclause 2.3.
  132. */
  133. #define AKA_TEMP_SIZE 16
  134. typedef uint8_t AKA_TEMP_T[AKA_TEMP_SIZE + 1];
  135. /**@def AKA_AUTS_SIZE
  136. * Authentication Token. A 112 bit value generated by the client
  137. upon experiencing an SQN synchronization failure.
  138. * Defined in RFC 3310 subclause 3.4
  139. */
  140. #define AKA_AUTS_SIZE 14
  141. typedef uint8_t AKA_AUTS_T[AKA_AUTS_SIZE + 1];
  142. /**@def AKA_AUTN_SIZE
  143. * Authentication Token. A 128 bit value generated by the AuC, which
  144. together with the RAND parameter authenticates the server to the client.
  145. * Defined in RFC 3310 subclause 3.4
  146. */
  147. #define AKA_AUTN_SIZE 16
  148. typedef uint8_t AKA_AUTN_T[AKA_AUTN_SIZE + 1];
  149. #define AKA_XXX_DECLARE(name) AKA_##name##_T name
  150. #define AKA_XXX_BZERO(name) memset(name, '\0', AKA_##name##_SIZE + 1)
  151. void f1 ( uint8_t k[16], uint8_t rand[16], uint8_t sqn[6], uint8_t amf[2],
  152. uint8_t mac_a[8] );
  153. void f2345 ( uint8_t k[16], uint8_t rand[16],
  154. uint8_t res[8], uint8_t ck[16], uint8_t ik[16], uint8_t ak[6] );
  155. void f1star( uint8_t k[16], uint8_t rand[16], uint8_t sqn[6], uint8_t amf[2],
  156. uint8_t mac_s[8] );
  157. void f5star( uint8_t k[16], uint8_t rand[16],
  158. uint8_t ak[6] );
  159. void ComputeOPc( uint8_t op_c[16] );
  160. void ComputeOP( uint8_t op[16] );
  161. TSIP_END_DECLS
  162. #endif /* TINYSIP_AUTHENTICATION_MILENAGE_H */