jpake.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. BIGNUM *gr; /* g^r (r random) */
  22. BIGNUM *b; /* b = r - x*h, h=hash(g, g^r, g^x, name) */
  23. } JPAKE_ZKP;
  24. typedef struct {
  25. BIGNUM *gx; /* g^x in step 1, g^(xa + xc + xd) * xb * s
  26. * in step 2 */
  27. JPAKE_ZKP zkpx; /* ZKP(x) or ZKP(xb * s) */
  28. } JPAKE_STEP_PART;
  29. typedef struct {
  30. JPAKE_STEP_PART p1; /* g^x3, ZKP(x3) or g^x1, ZKP(x1) */
  31. JPAKE_STEP_PART p2; /* g^x4, ZKP(x4) or g^x2, ZKP(x2) */
  32. } JPAKE_STEP1;
  33. typedef JPAKE_STEP_PART JPAKE_STEP2;
  34. typedef struct {
  35. unsigned char hhk[SHA_DIGEST_LENGTH];
  36. } JPAKE_STEP3A;
  37. typedef struct {
  38. unsigned char hk[SHA_DIGEST_LENGTH];
  39. } JPAKE_STEP3B;
  40. /* Parameters are copied */
  41. JPAKE_CTX *JPAKE_CTX_new(const char *name, const char *peer_name,
  42. const BIGNUM *p, const BIGNUM *g, const BIGNUM *q,
  43. const BIGNUM *secret);
  44. void JPAKE_CTX_free(JPAKE_CTX *ctx);
  45. /*
  46. * Note that JPAKE_STEP1 can be used multiple times before release
  47. * without another init.
  48. */
  49. void JPAKE_STEP1_init(JPAKE_STEP1 *s1);
  50. int JPAKE_STEP1_generate(JPAKE_STEP1 *send, JPAKE_CTX *ctx);
  51. int JPAKE_STEP1_process(JPAKE_CTX *ctx, const JPAKE_STEP1 *received);
  52. void JPAKE_STEP1_release(JPAKE_STEP1 *s1);
  53. /*
  54. * Note that JPAKE_STEP2 can be used multiple times before release
  55. * without another init.
  56. */
  57. void JPAKE_STEP2_init(JPAKE_STEP2 *s2);
  58. int JPAKE_STEP2_generate(JPAKE_STEP2 *send, JPAKE_CTX *ctx);
  59. int JPAKE_STEP2_process(JPAKE_CTX *ctx, const JPAKE_STEP2 *received);
  60. void JPAKE_STEP2_release(JPAKE_STEP2 *s2);
  61. /*
  62. * Optionally verify the shared key. If the shared secrets do not
  63. * match, the two ends will disagree about the shared key, but
  64. * otherwise the protocol will succeed.
  65. */
  66. void JPAKE_STEP3A_init(JPAKE_STEP3A *s3a);
  67. int JPAKE_STEP3A_generate(JPAKE_STEP3A *send, JPAKE_CTX *ctx);
  68. int JPAKE_STEP3A_process(JPAKE_CTX *ctx, const JPAKE_STEP3A *received);
  69. void JPAKE_STEP3A_release(JPAKE_STEP3A *s3a);
  70. void JPAKE_STEP3B_init(JPAKE_STEP3B *s3b);
  71. int JPAKE_STEP3B_generate(JPAKE_STEP3B *send, JPAKE_CTX *ctx);
  72. int JPAKE_STEP3B_process(JPAKE_CTX *ctx, const JPAKE_STEP3B *received);
  73. void JPAKE_STEP3B_release(JPAKE_STEP3B *s3b);
  74. /*
  75. * the return value belongs to the library and will be released when
  76. * ctx is released, and will change when a new handshake is performed.
  77. */
  78. const BIGNUM *JPAKE_get_shared_key(JPAKE_CTX *ctx);
  79. /* BEGIN ERROR CODES */
  80. /*
  81. * The following lines are auto generated by the script mkerr.pl. Any changes
  82. * made after this point may be overwritten when the script is next run.
  83. */
  84. void ERR_load_JPAKE_strings(void);
  85. /* Error codes for the JPAKE functions. */
  86. /* Function codes. */
  87. # define JPAKE_F_JPAKE_STEP1_PROCESS 101
  88. # define JPAKE_F_JPAKE_STEP2_PROCESS 102
  89. # define JPAKE_F_JPAKE_STEP3A_PROCESS 103
  90. # define JPAKE_F_JPAKE_STEP3B_PROCESS 104
  91. # define JPAKE_F_VERIFY_ZKP 100
  92. /* Reason codes. */
  93. # define JPAKE_R_G_TO_THE_X3_IS_NOT_LEGAL 108
  94. # define JPAKE_R_G_TO_THE_X4_IS_NOT_LEGAL 109
  95. # define JPAKE_R_G_TO_THE_X4_IS_ONE 105
  96. # define JPAKE_R_HASH_OF_HASH_OF_KEY_MISMATCH 106
  97. # define JPAKE_R_HASH_OF_KEY_MISMATCH 107
  98. # define JPAKE_R_VERIFY_B_FAILED 102
  99. # define JPAKE_R_VERIFY_X3_FAILED 103
  100. # define JPAKE_R_VERIFY_X4_FAILED 104
  101. # define JPAKE_R_ZKP_VERIFY_FAILED 100
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105. #endif