aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2016-11-18 12:48:53 +0100
committerDennis Brentjes <d.brentjes@gmail.com>2016-11-18 12:48:53 +0100
commit127b6d6d55456eb49104d380157a63ef1d1ac546 (patch)
treef51c446644ae971658aa03d0bf769b3a4d0bef9c
parent6d55dcba54ceaccc9d90ea7c2f1746524a6e81e3 (diff)
downloadcmix-127b6d6d55456eb49104d380157a63ef1d1ac546.tar.gz
cmix-127b6d6d55456eb49104d380157a63ef1d1ac546.tar.bz2
cmix-127b6d6d55456eb49104d380157a63ef1d1ac546.zip
Code cleanup
-rw-r--r--libcmix-crypto/elgamal/gcrypt/gcrypt_elgamal.c28
-rw-r--r--libcmix/cmix.c30
-rw-r--r--libcmix/cmix.h25
3 files changed, 0 insertions, 83 deletions
diff --git a/libcmix-crypto/elgamal/gcrypt/gcrypt_elgamal.c b/libcmix-crypto/elgamal/gcrypt/gcrypt_elgamal.c
index e25ba72..21a7618 100644
--- a/libcmix-crypto/elgamal/gcrypt/gcrypt_elgamal.c
+++ b/libcmix-crypto/elgamal/gcrypt/gcrypt_elgamal.c
@@ -78,7 +78,6 @@ struct KeyPair gcrypt_elgamal_create_keypair() {
error = gcry_mpi_scan(&x, GCRYMPI_FMT_USG, bytes, nr_bytes, &parse_error_offset);
gcry_free(bytes);
check(error);
- gcry_mpi_mod(x, x, p); //bias needs to be removed.
} while(gcry_mpi_cmp_ui(x, 0) == 0 || gcry_mpi_cmp(x, p) != -1);
gcry_mpi_t y = gcry_mpi_new(0);
gcry_mpi_powm(y, g, x, p);
@@ -123,7 +122,6 @@ void* gcrypt_elgamal_array_to_element(char const* buffer, size_t len, bool secur
gcry_mpi_t mpi;
error = gcry_mpi_scan(&mpi, GCRYMPI_FMT_USG, buffer, len, &error_pos);
- //gcry_mpi_set_flag(mpi, GCRYMPI_FLAG_SECURE);
check(error);
return mpi;
@@ -151,13 +149,11 @@ void* gcrypt_elgamal_get_group_element(bool secure) {
void* bytes = gcry_random_bytes_secure(nr_bytes, GCRY_VERY_STRONG_RANDOM);
error = gcry_mpi_scan(&a, GCRYMPI_FMT_USG, bytes, nr_bytes, &parse_error_offset);
check(error);
- gcry_mpi_mod(a, a, p); //BIAS REMOVE THIS.
gcry_free(bytes);
} while(gcry_mpi_cmp_ui(a, 0) == 0 || gcry_mpi_cmp(a, p) != -1);
//random bytes generated with GCRY{,_VERY}_STRONG_RANDOM are generated in "secure memory"
//so secure is unused.
-
return a;
}
@@ -177,9 +173,6 @@ GroupElement gcrypt_elgamal_multiply(GroupElement lh, GroupElement rh, bool secu
}
GroupElement gcrypt_elgamal_get_decryption_share(GroupElement r, GroupElement e) {
- //gcry_mpi_t inve = gcry_mpi_snew(0);
- //gcry_mpi_invm(inve, (gcry_mpi_t)e, p);
-
gcry_mpi_t inv_d = gcry_mpi_snew(0);
gcry_mpi_powm(inv_d, (gcry_mpi_t)r, (gcry_mpi_t)e, p);
@@ -255,27 +248,6 @@ void gcrypt_elgamal_encrypt(GroupElement* random_element, GroupElement* message_
gcry_mpi_release((gcry_mpi_t) random);
gcry_mpi_release(key_pow_random);
-
-/* gcry_error_t error;
- size_t parse_error_pos;
-
- gcry_sexp_t pubkey_expr;
- error = gcry_sexp_build(&pubkey_expr, &parse_error_pos, "(public-key (elg (p %M) (g %M) (y %M)))", p, g, key);
- check(error);
-
- gcry_sexp_t value_expr;
- error = gcry_sexp_build(&value_expr, &parse_error_pos, "(data (flags raw) (value %M))", value);
- check(error);
-
- gcry_sexp_t enc_expr;
- error = gcry_pk_encrypt(&enc_expr, value_expr, pubkey_expr);
- check(error);
-
- gcry_sexp_extract_param(enc_expr, NULL, "ab", random_element, message_element, NULL);
-
- gcry_sexp_release(enc_expr);
- gcry_sexp_release(value_expr);
- gcry_sexp_release(pubkey_expr); */
}
GroupElement gcrypt_elgamal_invert(GroupElement const x) {
diff --git a/libcmix/cmix.c b/libcmix/cmix.c
index 68a638f..2ba5fd9 100644
--- a/libcmix/cmix.c
+++ b/libcmix/cmix.c
@@ -5,32 +5,6 @@
#include <stdlib.h>
#include <stdio.h>
-enum cmix_error permutation(struct CMixBuffer b) {
- return no_error;
-}
-
-enum cmix_error get_message(char* message, struct CMixBuffer b, unsigned int index)
-{
- if(index >= b.message_length) {
- return index_out_of_range;
- }
-
- strncpy(message, b.buffer + index * b.message_length, b.message_length);
-
- return no_error;
-}
-
-enum cmix_error set_message(char const* message, struct CMixBuffer b, unsigned int index)
-{
- if(index >= b.message_length) {
- return index_out_of_range;
- }
-
- strncpy(b.buffer + index * b.message_length, message, b.message_length);
-
- return no_error;
-}
-
enum cmix_error calculate_shared_key_part(struct Bignum* result, struct Bignum partial_shared, struct Bignum my_share, struct Bignum mod)
{
if(multiply_mod(result, partial_shared, my_share, mod) != NoError) {
@@ -285,13 +259,10 @@ enum cmix_error key_exchange_initiator(struct CMixContext const* ctx, GroupEleme
enum cmix_error post_process(struct CMixContext* ctx, char* r_out, char* m_out, char const* r_epirs, char const* m_epirs, size_t index) {
GroupElement x = ctx->api.array_to_element(r_epirs, get_group_element_array_size(ctx), true);
GroupElement D = ctx->api.get_decryption_share(x, ctx->keypair.sec);
- //element_to_buffer(ctx, r_out, D);
GroupElement msg = ctx->api.array_to_element(m_epirs, get_group_element_array_size(ctx), true);
GroupElement pirs = ctx->api.multiply(D, msg, true);
element_to_buffer(ctx, m_out, pirs);
- //GroupElement new_r = ctx->api.multiply(x, D, true);
- //element_to_buffer(ctx, r_out, new_r);
memcpy(r_out, r_epirs, get_group_element_array_size(ctx));
@@ -300,7 +271,6 @@ enum cmix_error post_process(struct CMixContext* ctx, char* r_out, char* m_out,
ctx->api.free_group_element(x);
ctx->api.free_group_element(D);
ctx->api.free_group_element(msg);
- //ctx->api.free_group_element(new_r);
return no_error;
}
diff --git a/libcmix/cmix.h b/libcmix/cmix.h
index 53212fe..f3d071d 100644
--- a/libcmix/cmix.h
+++ b/libcmix/cmix.h
@@ -35,31 +35,6 @@ enum cmix_error {
};
/*!
- * \brief permutate mixes the messages before sending the messages.
- * \param[in,out] b A buffer of \p nr_messages messages, each message of length *message_len*
- * \return no_error
- */
-enum cmix_error permute(struct CMixBuffer b);
-
-/*!
- * \brief get_message takes the \p index message of the buffer \p b copies it into \p message
- * \param[out] message is the output buffer that has to hold at least \p b.message_length bytes.
- * \param[in] b is the buffer from which to copy the message.
- * \param[in] index is the index of the message to copy.
- * \return index_out_of_range if \p index is greater than or equal to \p b.nr_messages , otherwise no_error.
- */
-enum cmix_error get_message(char* message, struct CMixBuffer b, unsigned int index);
-
-/*!
- * \brief set_message set the \p index message of the buffer to a copy of \p message.
- * \param[in] message The message to set the part of the buffer to.
- * \param[in,out] b The buffer
- * \param[in] index The index into the buffer
- * \return index_out_of_range if \p index is greater than or equal to \p b.nr_messages , otherwise no_error.
- */
-enum cmix_error set_message(char const* message, struct CMixBuffer b, unsigned int index);
-
-/*!
* \brief calculate_shared_key_part Calculates (partly) the shared key which is needed by all the nodes.
* \param result Storage for the result
* \param partial_shared The shared key so far.