coding style
This commit is contained in:
parent
557fbe2cc3
commit
338c95de41
91
crypto.c
91
crypto.c
@ -37,6 +37,11 @@ struct brandt_ec_pkey {
|
||||
gcry_mpi_point_t ec_gen;
|
||||
gcry_ctx_t ec_ctx;
|
||||
|
||||
/**
|
||||
* brandt_crypto_init
|
||||
*
|
||||
*
|
||||
*/
|
||||
void
|
||||
brandt_crypto_init ()
|
||||
{
|
||||
@ -154,29 +159,28 @@ brandt_mpi_scan_unsigned (gcry_mpi_t *result, const void *data, size_t size)
|
||||
brandt_assert_gpgerr (rc);
|
||||
}
|
||||
|
||||
/*
|
||||
gcry_mpi_point_t
|
||||
deserialize_point(const struct brandt_point* data, const int len)
|
||||
{
|
||||
gcry_sexp_t s;
|
||||
gcry_ctx_t ctx;
|
||||
gcry_mpi_point_t ret;
|
||||
gcry_error_t rc;
|
||||
//gcry_mpi_point_t
|
||||
//deserialize_point(const struct brandt_point* data, const int len)
|
||||
//{
|
||||
// gcry_sexp_t s;
|
||||
// gcry_ctx_t ctx;
|
||||
// gcry_mpi_point_t ret;
|
||||
// gcry_error_t rc;
|
||||
//
|
||||
// rc = gcry_sexp_build(&s, NULL, "(public-key(ecc(curve " CURVE ")(q %b)))",
|
||||
// len, data);
|
||||
// brandt_assert_gpgerr(rc);
|
||||
//
|
||||
// rc = gcry_mpi_ec_new(&ctx, s, NULL);
|
||||
// brandt_assert_gpgerr(rc);
|
||||
// gcry_sexp_release(s);
|
||||
//
|
||||
// ret = gcry_mpi_ec_get_point("q", ctx, 0);
|
||||
// brandt_assert(ret);
|
||||
// gcry_ctx_release(ctx);
|
||||
// return ret;
|
||||
//}
|
||||
|
||||
rc = gcry_sexp_build(&s, NULL, "(public-key(ecc(curve " CURVE ")(q %b)))",
|
||||
len, data);
|
||||
brandt_assert_gpgerr(rc);
|
||||
|
||||
rc = gcry_mpi_ec_new(&ctx, s, NULL);
|
||||
brandt_assert_gpgerr(rc);
|
||||
gcry_sexp_release(s);
|
||||
|
||||
ret = gcry_mpi_ec_get_point("q", ctx, 0);
|
||||
brandt_assert(ret);
|
||||
gcry_ctx_release(ctx);
|
||||
return ret;
|
||||
}
|
||||
*/
|
||||
|
||||
/* --- EC --- */
|
||||
|
||||
@ -238,6 +242,11 @@ key_from_sexp (gcry_mpi_t *array, gcry_sexp_t sexp, const char *topname,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* brandt_ec_skey_create
|
||||
*
|
||||
* @param[out] skey where to store the generated secret key
|
||||
*/
|
||||
void
|
||||
brandt_ec_skey_create (gcry_mpi_t *skey)
|
||||
{
|
||||
@ -259,14 +268,24 @@ brandt_ec_skey_create (gcry_mpi_t* skey)
|
||||
gcry_sexp_release (priv_sexp);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* brandt_ec_pkey_compute
|
||||
*
|
||||
* @param pkey TODO
|
||||
* @param skey TODO
|
||||
*/
|
||||
void
|
||||
brandt_ec_pkey_compute (gcry_mpi_point_t *pkey, const gcry_mpi_t skey)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* brandt_ec_keypair_create
|
||||
*
|
||||
* @param[out] pkey where to store the generated public key
|
||||
* @param[out] skey where to store the generated secret key
|
||||
*/
|
||||
void
|
||||
brandt_ec_keypair_create (gcry_mpi_point_t *pkey, gcry_mpi_t *skey)
|
||||
{
|
||||
@ -295,9 +314,16 @@ brandt_ec_keypair_create (gcry_mpi_point_t* pkey, gcry_mpi_t* skey)
|
||||
gcry_ctx_release (ctx);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* brandt_ec_keypair_create_base
|
||||
*
|
||||
* @param[out] pkey where to store the generated public key
|
||||
* @param[out] skey where to store the generated secret key
|
||||
* @param[in] base which base point should be used to calculate the public key
|
||||
*/
|
||||
void
|
||||
brandt_ec_keypair_create_base (gcry_mpi_point_t* pkey, gcry_mpi_t* skey, const gcry_mpi_point_t base)
|
||||
brandt_ec_keypair_create_base (gcry_mpi_point_t *pkey, gcry_mpi_t *skey,
|
||||
const gcry_mpi_point_t base)
|
||||
{
|
||||
brandt_ec_skey_create (skey);
|
||||
brandt_assert (*skey);
|
||||
@ -306,7 +332,14 @@ brandt_ec_keypair_create_base (gcry_mpi_point_t* pkey, gcry_mpi_t* skey, const g
|
||||
gcry_mpi_ec_mul (*pkey, *skey, base, ec_ctx);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* brandt_ec_point_cmp compares two curve points
|
||||
*
|
||||
* @param[in] a the first point
|
||||
* @param[in] b the second point
|
||||
* @return 0 if @a a and @a b represent the same point on the curve, something
|
||||
* else otherwise
|
||||
*/
|
||||
int
|
||||
brandt_ec_point_cmp (const gcry_mpi_point_t a, const gcry_mpi_point_t b)
|
||||
{
|
||||
@ -323,7 +356,8 @@ brandt_ec_point_cmp (const gcry_mpi_point_t a, const gcry_mpi_point_t b)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!gcry_mpi_ec_get_affine(ax, ay, a, ec_ctx) && !gcry_mpi_ec_get_affine(bx, by, b, ec_ctx))
|
||||
if (!gcry_mpi_ec_get_affine (ax, ay, a, ec_ctx)
|
||||
&& !gcry_mpi_ec_get_affine (bx, by, b, ec_ctx))
|
||||
{
|
||||
ret = gcry_mpi_cmp (ax, bx) || gcry_mpi_cmp (ay, by);
|
||||
}
|
||||
@ -335,7 +369,6 @@ brandt_ec_point_cmp (const gcry_mpi_point_t a, const gcry_mpi_point_t b)
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert the given private key from the network format to the
|
||||
* S-expression that can be used by libgcrypt.
|
||||
|
72
smc.c
72
smc.c
@ -22,13 +22,25 @@
|
||||
#include <gcrypt.h>
|
||||
|
||||
#include "crypto.h"
|
||||
#include "util.h"
|
||||
#include "smc.h"
|
||||
#include "util.h"
|
||||
|
||||
extern gcry_ctx_t ec_ctx;
|
||||
|
||||
/**
|
||||
* smc_zkp_dl
|
||||
*
|
||||
* @param v TODO
|
||||
* @param g TODO
|
||||
* @param x TODO
|
||||
* @param a TODO
|
||||
* @param c TODO
|
||||
* @param r TODO
|
||||
*/
|
||||
void
|
||||
smc_zkp_dl (gcry_mpi_point_t v, gcry_mpi_point_t g, gcry_mpi_t x, gcry_mpi_point_t *a, gcry_mpi_t *c, gcry_mpi_t *r)
|
||||
smc_zkp_dl (gcry_mpi_point_t v, gcry_mpi_point_t g, gcry_mpi_t x,
|
||||
gcry_mpi_point_t *a, gcry_mpi_t *c,
|
||||
gcry_mpi_t *r)
|
||||
{
|
||||
gcry_mpi_t z = gcry_mpi_new (0);
|
||||
|
||||
@ -42,8 +54,20 @@ smc_zkp_dl (gcry_mpi_point_t v, gcry_mpi_point_t g, gcry_mpi_t x, gcry_mpi_point
|
||||
gcry_mpi_release (z);
|
||||
}
|
||||
|
||||
/**
|
||||
* smc_zkp_dl_check
|
||||
*
|
||||
* @param v TODO
|
||||
* @param g TODO
|
||||
* @param a TODO
|
||||
* @param c TODO
|
||||
* @param r TODO
|
||||
* @return 0 if the proof is correct, something else otherwise
|
||||
*/
|
||||
int
|
||||
smc_zkp_dl_check (gcry_mpi_point_t v, gcry_mpi_point_t g, gcry_mpi_point_t a, gcry_mpi_t c, gcry_mpi_t r)
|
||||
smc_zkp_dl_check (gcry_mpi_point_t v, gcry_mpi_point_t g, gcry_mpi_point_t a,
|
||||
gcry_mpi_t c,
|
||||
gcry_mpi_t r)
|
||||
{
|
||||
int ret;
|
||||
gcry_mpi_point_t left = gcry_mpi_point_new (0);
|
||||
@ -60,25 +84,23 @@ smc_zkp_dl_check (gcry_mpi_point_t v, gcry_mpi_point_t g, gcry_mpi_point_t a, gc
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
GEN
|
||||
smc_hextodec (const char *s)
|
||||
{
|
||||
size_t i;
|
||||
char c;
|
||||
pari_sp ltop = avma;
|
||||
GEN ret = gen_0;
|
||||
|
||||
for (i = 0; i < strlen (s); i++)
|
||||
{
|
||||
errno = 0;
|
||||
if (1 != sscanf (&s[i], "%1hhx", &c))
|
||||
{
|
||||
brandt_eprintf ("failed to parse hex (\"%s\") to decimal:", s);
|
||||
return NULL;
|
||||
}
|
||||
ret = addis (shifti (ret, 4), c);
|
||||
}
|
||||
return gerepilecopy (ltop, ret);
|
||||
}
|
||||
*/
|
||||
//GEN
|
||||
//smc_hextodec (const char *s)
|
||||
//{
|
||||
// size_t i;
|
||||
// char c;
|
||||
// pari_sp ltop = avma;
|
||||
// GEN ret = gen_0;
|
||||
//
|
||||
// for (i = 0; i < strlen (s); i++)
|
||||
// {
|
||||
// errno = 0;
|
||||
// if (1 != sscanf (&s[i], "%1hhx", &c))
|
||||
// {
|
||||
// brandt_eprintf ("failed to parse hex (\"%s\") to decimal:", s);
|
||||
// return NULL;
|
||||
// }
|
||||
// ret = addis (shifti (ret, 4), c);
|
||||
// }
|
||||
// return gerepilecopy (ltop, ret);
|
||||
//}
|
||||
|
22
smc.h
22
smc.h
@ -1,3 +1,23 @@
|
||||
/* This file is part of libbrandt.
|
||||
* Copyright (C) 2016 GNUnet e.V.
|
||||
*
|
||||
* libbrandt is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* libbrandt is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* libbrandt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file smc.h
|
||||
* @brief describes the secure multiparty computation interface.
|
||||
*/
|
||||
|
||||
#ifndef _BRANDT_SMC_H
|
||||
#define _BRANDT_SMC_H
|
||||
@ -7,4 +27,4 @@
|
||||
void smc_zkp_dl (gcry_mpi_point_t v, gcry_mpi_point_t g, gcry_mpi_t x, gcry_mpi_point_t *a, gcry_mpi_t *c, gcry_mpi_t *r);
|
||||
int smc_zkp_dl_check (gcry_mpi_point_t v, gcry_mpi_point_t g, gcry_mpi_point_t a, gcry_mpi_t c, gcry_mpi_t r);
|
||||
|
||||
#endif
|
||||
#endif // ifndef _BRANDT_SMC_H
|
||||
|
24
test.h
24
test.h
@ -1,3 +1,23 @@
|
||||
/* This file is part of libbrandt.
|
||||
* Copyright (C) 2016 GNUnet e.V.
|
||||
*
|
||||
* libbrandt is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* libbrandt is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* libbrandt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file test.h
|
||||
* @brief Some helpers for running tests
|
||||
*/
|
||||
#ifndef _BRANDT_TEST_H
|
||||
#define _BRANDT_TEST_H
|
||||
|
||||
@ -7,6 +27,6 @@ int tests_run = 0;
|
||||
int ret = 0;
|
||||
|
||||
#define check(cond, message) do { if (!(cond)) { fputs (message, stderr); fputc ('\n', stderr); return 0; } } while (0)
|
||||
#define run(test) do { tests_run++; if (!test()) ret = 1; } while (0)
|
||||
#define run(test) do { tests_run++; if (!test ()) { ret = 1; } } while (0)
|
||||
|
||||
#endif
|
||||
#endif // ifndef _BRANDT_TEST_H
|
||||
|
@ -1,4 +1,23 @@
|
||||
/* This file is part of libbrandt.
|
||||
* Copyright (C) 2016 GNUnet e.V.
|
||||
*
|
||||
* libbrandt is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* libbrandt is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* libbrandt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file test_crypto.c
|
||||
* @brief testing crypto and smc functions.
|
||||
*/
|
||||
#include "brandt.h"
|
||||
#include "crypto.h"
|
||||
#include "smc.h"
|
||||
|
@ -1154,7 +1154,7 @@ nl_after_func_body_one_liner = 0 # number
|
||||
|
||||
# The minimum number of newlines before a multi-line comment.
|
||||
# Doesn't apply if after a brace open or another multi-line comment.
|
||||
nl_before_block_comment = 0 # number
|
||||
nl_before_block_comment = 1 # number
|
||||
|
||||
# The minimum number of newlines before a single-line C comment.
|
||||
# Doesn't apply if after a brace open or other single-line C comments.
|
||||
@ -1320,7 +1320,7 @@ cmt_cpp_nl_start = false # false/true
|
||||
cmt_cpp_nl_end = false # false/true
|
||||
|
||||
# Whether to change cpp-comments into c-comments
|
||||
cmt_cpp_to_c = true # false/true
|
||||
cmt_cpp_to_c = false # false/true
|
||||
|
||||
# Whether to put a star on subsequent comment lines
|
||||
cmt_star_cont = true # false/true
|
||||
|
Loading…
Reference in New Issue
Block a user