summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/lib5.c14
-rw-r--r--lib/lib5.h1
-rw-r--r--set5/task37.c37
3 files changed, 52 insertions, 0 deletions
diff --git a/lib/lib5.c b/lib/lib5.c
index f637469..04c7806 100644
--- a/lib/lib5.c
+++ b/lib/lib5.c
@@ -265,6 +265,20 @@ void srp_compute_uH(struct srp_context *srpc)
BN_bin2bn(uH, 20, srpc->u);
}
+void srp_client_s_0_prepare_k(struct srp_context *srpc)
+{
+ SHA1Context sha1;
+ BIGNUM *S = BN_new();
+ BN_zero(S);
+
+ char *s_str = malloc(BN_num_bytes(S));
+ BN_bn2bin(S, s_str);
+ SHA1Reset(&sha1);
+ SHA1Input(&sha1, s_str, BN_num_bytes(S));
+ SHA1Result(&sha1);
+ memcpy(srpc->client_K, &(sha1.Message_Digest), 20);
+}
+
void srp_client_prepare_k(struct srp_context *srpc, char *password)
{
SHA1Context sha1;
diff --git a/lib/lib5.h b/lib/lib5.h
index 4aaa7d6..bf71802 100644
--- a/lib/lib5.h
+++ b/lib/lib5.h
@@ -116,4 +116,5 @@ void srp_compute_uH(struct srp_context *srpc);
void srp_client_prepare_k(struct srp_context *srpc, char *password);
void srp_server_prepare_k(struct srp_context *srpc);
void srp_context_init(struct srp_context *s);
+void srp_client_s_0_prepare_k(struct srp_context *srpc);
#endif
diff --git a/set5/task37.c b/set5/task37.c
new file mode 100644
index 0000000..ccfc66f
--- /dev/null
+++ b/set5/task37.c
@@ -0,0 +1,37 @@
+#include "../lib/lib.h"
+#include "../lib/lib2.h"
+#include "../lib/lib3.h"
+#include "../lib/lib4.h"
+#include "../lib/lib5.h"
+#include <time.h>
+
+int main()
+{
+ struct srp_context srpc;
+ char *email = "test@example.com";
+ char *password = "adfasdkfjh";
+ char sK[41];
+ char cK[41];
+ out = BIO_new(BIO_s_file());
+ BIO_set_fp(out, stdout, BIO_NOCLOSE);
+
+ ctx = BN_CTX_new();
+
+ srp_context_init(&srpc);
+ srp_server_init(email, password, &srpc);
+ srp_client_send1(email, &srpc);
+ /** setting A to zero or kN yields to a zero S whatever the password is
+ * So we can set S also to 0 to get the same session key as the server
+ **/
+ BN_zero(srpc.A);
+ BN_copy(srpc.A, srpc.N);
+ srp_server_send1(&srpc);
+ srp_compute_uH(&srpc);
+ srp_client_s_0_prepare_k(&srpc);
+ srp_server_prepare_k(&srpc);
+ // set client session key also to 0
+ hex_binary_to_string(srpc.client_K, cK, 20);
+ hex_binary_to_string(srpc.server_K, sK, 20);
+ printf("cK: %s\n", cK);
+ printf("sK: %s\n", sK);
+}