summaryrefslogtreecommitdiffstats
path: root/lib/libssl/src/crypto/ecdsa/ecs_lib.c
diff options
context:
space:
mode:
authorjsing <jsing@openbsd.org>2015-02-08 13:35:06 +0000
committerjsing <jsing@openbsd.org>2015-02-08 13:35:06 +0000
commit63d9167de8463531a4634223ac89b01234a50ffc (patch)
treef5b708280dcad7afbee14aa1cfad0de0ab009a9b /lib/libssl/src/crypto/ecdsa/ecs_lib.c
parentFix mfi ioctl to set drive state properly. (diff)
downloadwireguard-openbsd-63d9167de8463531a4634223ac89b01234a50ffc.tar.xz
wireguard-openbsd-63d9167de8463531a4634223ac89b01234a50ffc.zip
Lob a KNF grenade into the ecdsa code.
Diffstat (limited to 'lib/libssl/src/crypto/ecdsa/ecs_lib.c')
-rw-r--r--lib/libssl/src/crypto/ecdsa/ecs_lib.c124
1 files changed, 64 insertions, 60 deletions
diff --git a/lib/libssl/src/crypto/ecdsa/ecs_lib.c b/lib/libssl/src/crypto/ecdsa/ecs_lib.c
index 6cdf4c124b0..dba888cb48a 100644
--- a/lib/libssl/src/crypto/ecdsa/ecs_lib.c
+++ b/lib/libssl/src/crypto/ecdsa/ecs_lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ecs_lib.c,v 1.8 2015/02/07 13:19:15 doug Exp $ */
+/* $OpenBSD: ecs_lib.c,v 1.9 2015/02/08 13:35:07 jsing Exp $ */
/* ====================================================================
* Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
*
@@ -7,7 +7,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -70,21 +70,23 @@ static void *ecdsa_data_new(void);
static void *ecdsa_data_dup(void *);
static void ecdsa_data_free(void *);
-void ECDSA_set_default_method(const ECDSA_METHOD *meth)
+void
+ECDSA_set_default_method(const ECDSA_METHOD *meth)
{
default_ECDSA_method = meth;
}
-const ECDSA_METHOD *ECDSA_get_default_method(void)
+const ECDSA_METHOD *
+ECDSA_get_default_method(void)
{
- if(!default_ECDSA_method)
- {
+ if (!default_ECDSA_method) {
default_ECDSA_method = ECDSA_OpenSSL();
- }
+ }
return default_ECDSA_method;
}
-int ECDSA_set_method(EC_KEY *eckey, const ECDSA_METHOD *meth)
+int
+ECDSA_set_method(EC_KEY *eckey, const ECDSA_METHOD *meth)
{
ECDSA_DATA *ecdsa;
@@ -94,26 +96,25 @@ int ECDSA_set_method(EC_KEY *eckey, const ECDSA_METHOD *meth)
return 0;
#ifndef OPENSSL_NO_ENGINE
- if (ecdsa->engine)
- {
+ if (ecdsa->engine) {
ENGINE_finish(ecdsa->engine);
ecdsa->engine = NULL;
}
#endif
- ecdsa->meth = meth;
+ ecdsa->meth = meth;
- return 1;
+ return 1;
}
-static ECDSA_DATA *ECDSA_DATA_new_method(ENGINE *engine)
+static ECDSA_DATA *
+ECDSA_DATA_new_method(ENGINE *engine)
{
ECDSA_DATA *ret;
ret = malloc(sizeof(ECDSA_DATA));
- if (ret == NULL)
- {
+ if (ret == NULL) {
ECDSAerr(ECDSA_F_ECDSA_DATA_NEW_METHOD, ERR_R_MALLOC_FAILURE);
- return(NULL);
+ return (NULL);
}
ret->init = NULL;
@@ -123,12 +124,11 @@ static ECDSA_DATA *ECDSA_DATA_new_method(ENGINE *engine)
#ifndef OPENSSL_NO_ENGINE
if (!ret->engine)
ret->engine = ENGINE_get_default_ECDSA();
- if (ret->engine)
- {
+ if (ret->engine) {
ret->meth = ENGINE_get_ECDSA(ret->engine);
- if (!ret->meth)
- {
- ECDSAerr(ECDSA_F_ECDSA_DATA_NEW_METHOD, ERR_R_ENGINE_LIB);
+ if (!ret->meth) {
+ ECDSAerr(ECDSA_F_ECDSA_DATA_NEW_METHOD,
+ ERR_R_ENGINE_LIB);
ENGINE_finish(ret->engine);
free(ret);
return NULL;
@@ -138,15 +138,17 @@ static ECDSA_DATA *ECDSA_DATA_new_method(ENGINE *engine)
ret->flags = ret->meth->flags;
CRYPTO_new_ex_data(CRYPTO_EX_INDEX_ECDSA, ret, &ret->ex_data);
- return(ret);
+ return (ret);
}
-static void *ecdsa_data_new(void)
+static void *
+ecdsa_data_new(void)
{
return (void *)ECDSA_DATA_new_method(NULL);
}
-static void *ecdsa_data_dup(void *data)
+static void *
+ecdsa_data_dup(void *data)
{
ECDSA_DATA *r = (ECDSA_DATA *)data;
@@ -157,7 +159,8 @@ static void *ecdsa_data_dup(void *data)
return ecdsa_data_new();
}
-static void ecdsa_data_free(void *data)
+static void
+ecdsa_data_free(void *data)
{
ECDSA_DATA *r = (ECDSA_DATA *)data;
@@ -172,38 +175,37 @@ static void ecdsa_data_free(void *data)
free(r);
}
-ECDSA_DATA *ecdsa_check(EC_KEY *key)
+ECDSA_DATA *
+ecdsa_check(EC_KEY *key)
{
ECDSA_DATA *ecdsa_data;
-
+
void *data = EC_KEY_get_key_method_data(key, ecdsa_data_dup,
- ecdsa_data_free, ecdsa_data_free);
- if (data == NULL)
- {
+ ecdsa_data_free, ecdsa_data_free);
+ if (data == NULL) {
ecdsa_data = (ECDSA_DATA *)ecdsa_data_new();
if (ecdsa_data == NULL)
return NULL;
data = EC_KEY_insert_key_method_data(key, (void *)ecdsa_data,
- ecdsa_data_dup, ecdsa_data_free, ecdsa_data_free);
- if (data != NULL)
- {
+ ecdsa_data_dup, ecdsa_data_free, ecdsa_data_free);
+ if (data != NULL) {
/* Another thread raced us to install the key_method
* data and won. */
ecdsa_data_free(ecdsa_data);
ecdsa_data = (ECDSA_DATA *)data;
- }
- }
- else
+ }
+ } else
ecdsa_data = (ECDSA_DATA *)data;
return ecdsa_data;
}
-int ECDSA_size(const EC_KEY *r)
+int
+ECDSA_size(const EC_KEY *r)
{
- int ret,i;
+ int ret, i;
ASN1_INTEGER bs;
- BIGNUM *order=NULL;
+ BIGNUM *order = NULL;
unsigned char buf[4];
const EC_GROUP *group;
@@ -213,48 +215,50 @@ int ECDSA_size(const EC_KEY *r)
if (group == NULL)
return 0;
- if ((order = BN_new()) == NULL) return 0;
- if (!EC_GROUP_get_order(group,order,NULL))
- {
+ if ((order = BN_new()) == NULL)
+ return 0;
+ if (!EC_GROUP_get_order(group, order, NULL)) {
BN_clear_free(order);
return 0;
- }
- i=BN_num_bits(order);
- bs.length=(i+7)/8;
- bs.data=buf;
- bs.type=V_ASN1_INTEGER;
+ }
+ i = BN_num_bits(order);
+ bs.length = (i + 7) / 8;
+ bs.data = buf;
+ bs.type = V_ASN1_INTEGER;
/* If the top bit is set the asn1 encoding is 1 larger. */
- buf[0]=0xff;
+ buf[0] = 0xff;
- i=i2d_ASN1_INTEGER(&bs,NULL);
- i+=i; /* r and s */
- ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
+ i = i2d_ASN1_INTEGER(&bs, NULL);
+ i += i; /* r and s */
+ ret = ASN1_object_size(1, i, V_ASN1_SEQUENCE);
BN_clear_free(order);
- return(ret);
+ return (ret);
}
-
-int ECDSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
- CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
+int
+ECDSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
+ CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
{
return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_ECDSA, argl, argp,
- new_func, dup_func, free_func);
+ new_func, dup_func, free_func);
}
-int ECDSA_set_ex_data(EC_KEY *d, int idx, void *arg)
+int
+ECDSA_set_ex_data(EC_KEY *d, int idx, void *arg)
{
ECDSA_DATA *ecdsa;
ecdsa = ecdsa_check(d);
if (ecdsa == NULL)
return 0;
- return(CRYPTO_set_ex_data(&ecdsa->ex_data,idx,arg));
+ return (CRYPTO_set_ex_data(&ecdsa->ex_data, idx, arg));
}
-void *ECDSA_get_ex_data(EC_KEY *d, int idx)
+void *
+ECDSA_get_ex_data(EC_KEY *d, int idx)
{
ECDSA_DATA *ecdsa;
ecdsa = ecdsa_check(d);
if (ecdsa == NULL)
return NULL;
- return(CRYPTO_get_ex_data(&ecdsa->ex_data,idx));
+ return (CRYPTO_get_ex_data(&ecdsa->ex_data, idx));
}