2
0

jpake.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Implement J-PAKE, as described in
  3. * http://grouper.ieee.org/groups/1363/Research/contributions/hao-ryan-2008.pdf
  4. *
  5. * With hints from http://www.cl.cam.ac.uk/~fh240/software/JPAKE2.java.
  6. */
  7. #ifndef HEADER_JPAKE_H
  8. #define HEADER_JPAKE_H
  9. #include <openssl/opensslconf.h>
  10. #ifdef OPENSSL_NO_JPAKE
  11. #error JPAKE is disabled.
  12. #endif
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #include <openssl/bn.h>
  17. #include <openssl/sha.h>
  18. typedef struct JPAKE_CTX JPAKE_CTX;
  19. /* Note that "g" in the ZKPs is not necessarily the J-PAKE g. */
  20. typedef struct
  21. {
  22. BIGNUM *gr; /* g^r (r random) */
  23. BIGNUM *b; /* b = r - x*h, h=hash(g, g^r, g^x, name) */
  24. } JPAKE_ZKP;
  25. typedef struct
  26. {
  27. BIGNUM *gx; /* g^x in step 1, g^(xa + xc + xd) * xb * s in step 2 */
  28. JPAKE_ZKP zkpx; /* ZKP(x) or ZKP(xb * s) */
  29. } JPAKE_STEP_PART;
  30. typedef struct
  31. {
  32. JPAKE_STEP_PART p1; /* g^x3, ZKP(x3) or g^x1, ZKP(x1) */
  33. JPAKE_STEP_PART p2; /* g^x4, ZKP(x4) or g^x2, ZKP(x2) */
  34. } JPAKE_STEP1;
  35. typedef JPAKE_STEP_PART JPAKE_STEP2;
  36. typedef struct
  37. {
  38. unsigned char hhk[SHA_DIGEST_LENGTH];
  39. } JPAKE_STEP3A;
  40. typedef struct
  41. {
  42. unsigned char hk[SHA_DIGEST_LENGTH];
  43. } JPAKE_STEP3B;
  44. /* Parameters are copied */
  45. JPAKE_CTX *JPAKE_CTX_new(const char *name, const char *peer_name,
  46. const BIGNUM *p, const BIGNUM *g, const BIGNUM *q,
  47. const BIGNUM *secret);
  48. void JPAKE_CTX_free(JPAKE_CTX *ctx);
  49. /*
  50. * Note that JPAKE_STEP1 can be used multiple times before release
  51. * without another init.
  52. */
  53. void JPAKE_STEP1_init(JPAKE_STEP1 *s1);
  54. int JPAKE_STEP1_generate(JPAKE_STEP1 *send, JPAKE_CTX *ctx);
  55. int JPAKE_STEP1_process(JPAKE_CTX *ctx, const JPAKE_STEP1 *received);
  56. void JPAKE_STEP1_release(JPAKE_STEP1 *s1);
  57. /*
  58. * Note that JPAKE_STEP2 can be used multiple times before release
  59. * without another init.
  60. */
  61. void JPAKE_STEP2_init(JPAKE_STEP2 *s2);
  62. int JPAKE_STEP2_generate(JPAKE_STEP2 *send, JPAKE_CTX *ctx);
  63. int JPAKE_STEP2_process(JPAKE_CTX *ctx, const JPAKE_STEP2 *received);
  64. void JPAKE_STEP2_release(JPAKE_STEP2 *s2);
  65. /*
  66. * Optionally verify the shared key. If the shared secrets do not
  67. * match, the two ends will disagree about the shared key, but
  68. * otherwise the protocol will succeed.
  69. */
  70. void JPAKE_STEP3A_init(JPAKE_STEP3A *s3a);
  71. int JPAKE_STEP3A_generate(JPAKE_STEP3A *send, JPAKE_CTX *ctx);
  72. int JPAKE_STEP3A_process(JPAKE_CTX *ctx, const JPAKE_STEP3A *received);
  73. void JPAKE_STEP3A_release(JPAKE_STEP3A *s3a);
  74. void JPAKE_STEP3B_init(JPAKE_STEP3B *s3b);
  75. int JPAKE_STEP3B_generate(JPAKE_STEP3B *send, JPAKE_CTX *ctx);
  76. int JPAKE_STEP3B_process(JPAKE_CTX *ctx, const JPAKE_STEP3B *received);
  77. void JPAKE_STEP3B_release(JPAKE_STEP3B *s3b);
  78. /*
  79. * the return value belongs to the library and will be released when
  80. * ctx is released, and will change when a new handshake is performed.
  81. */
  82. const BIGNUM *JPAKE_get_shared_key(JPAKE_CTX *ctx);
  83. /* BEGIN ERROR CODES */
  84. /* The following lines are auto generated by the script mkerr.pl. Any changes
  85. * made after this point may be overwritten when the script is next run.
  86. */
  87. void ERR_load_JPAKE_strings(void);
  88. /* Error codes for the JPAKE functions. */
  89. /* Function codes. */
  90. #define JPAKE_F_JPAKE_STEP1_PROCESS 101
  91. #define JPAKE_F_JPAKE_STEP2_PROCESS 102
  92. #define JPAKE_F_JPAKE_STEP3A_PROCESS 103
  93. #define JPAKE_F_JPAKE_STEP3B_PROCESS 104
  94. #define JPAKE_F_VERIFY_ZKP 100
  95. /* Reason codes. */
  96. #define JPAKE_R_G_TO_THE_X3_IS_NOT_LEGAL 108
  97. #define JPAKE_R_G_TO_THE_X4_IS_NOT_LEGAL 109
  98. #define JPAKE_R_G_TO_THE_X4_IS_ONE 105
  99. #define JPAKE_R_HASH_OF_HASH_OF_KEY_MISMATCH 106
  100. #define JPAKE_R_HASH_OF_KEY_MISMATCH 107
  101. #define JPAKE_R_VERIFY_B_FAILED 102
  102. #define JPAKE_R_VERIFY_X3_FAILED 103
  103. #define JPAKE_R_VERIFY_X4_FAILED 104
  104. #define JPAKE_R_ZKP_VERIFY_FAILED 100
  105. #ifdef __cplusplus
  106. }
  107. #endif
  108. #endif