summaryrefslogtreecommitdiff
path: root/lib/libssl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libssl')
-rw-r--r--lib/libssl/src/crypto/evp/e_gost2814789.c28
-rw-r--r--lib/libssl/src/crypto/evp/m_gost2814789.c25
-rw-r--r--lib/libssl/src/crypto/evp/m_gostr341194.c20
-rw-r--r--lib/libssl/src/crypto/evp/m_streebog.c32
-rw-r--r--lib/libssl/src/crypto/gost/gost2814789.c270
-rw-r--r--lib/libssl/src/crypto/gost/gost89_params.c15
-rw-r--r--lib/libssl/src/crypto/gost/gost89imit_ameth.c12
-rw-r--r--lib/libssl/src/crypto/gost/gost89imit_pmeth.c100
-rw-r--r--lib/libssl/src/crypto/gost/gostr341001_ameth.c92
-rw-r--r--lib/libssl/src/crypto/gost/gostr341001_key.c69
-rw-r--r--lib/libssl/src/crypto/gost/gostr341001_params.c20
-rw-r--r--lib/libssl/src/crypto/gost/gostr341001_pmeth.c69
-rw-r--r--lib/libssl/src/crypto/gost/gostr341194.c43
-rw-r--r--lib/libssl/src/crypto/gost/streebog.c85
14 files changed, 507 insertions, 373 deletions
diff --git a/lib/libssl/src/crypto/evp/e_gost2814789.c b/lib/libssl/src/crypto/evp/e_gost2814789.c
index 678c7af09dd..e1437b18d89 100644
--- a/lib/libssl/src/crypto/evp/e_gost2814789.c
+++ b/lib/libssl/src/crypto/evp/e_gost2814789.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: e_gost2814789.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */
+/* $OpenBSD: e_gost2814789.c,v 1.2 2014/11/09 23:06:50 miod Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -63,13 +63,14 @@ typedef struct {
int param_nid;
} EVP_GOST2814789_CTX;
-static int gost2814789_ctl(EVP_CIPHER_CTX *ctx,int type,int arg,void *ptr)
+static int
+gost2814789_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
{
EVP_GOST2814789_CTX *c = ctx->cipher_data;
switch (type) {
case EVP_CTRL_PBE_PRF_NID:
- if (ptr) {
+ if (ptr != NULL) {
*((int *)ptr) = NID_id_HMACGostR3411_94;
return 1;
} else {
@@ -137,7 +138,8 @@ int gost2814789_set_asn1_params(EVP_CIPHER_CTX * ctx, ASN1_TYPE * params)
return 1;
}
-int gost2814789_get_asn1_params(EVP_CIPHER_CTX * ctx, ASN1_TYPE * params)
+int
+gost2814789_get_asn1_params(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
{
int ret = -1;
int len;
@@ -145,20 +147,19 @@ int gost2814789_get_asn1_params(EVP_CIPHER_CTX * ctx, ASN1_TYPE * params)
EVP_GOST2814789_CTX *c = ctx->cipher_data;
unsigned char *p;
- if (ASN1_TYPE_get(params) != V_ASN1_SEQUENCE) {
+ if (ASN1_TYPE_get(params) != V_ASN1_SEQUENCE)
return ret;
- }
p = params->value.sequence->data;
gcp = d2i_GOST_CIPHER_PARAMS(NULL, (const unsigned char **)&p,
- params->value.sequence->length);
+ params->value.sequence->length);
len = gcp->iv->length;
if (len != ctx->cipher->iv_len) {
GOST_CIPHER_PARAMS_free(gcp);
GOSTerr(GOST_F_GOST89_GET_ASN1_PARAMETERS,
- GOST_R_INVALID_IV_LENGTH);
+ GOST_R_INVALID_IV_LENGTH);
return -1;
}
@@ -179,22 +180,23 @@ int gost2814789_get_asn1_params(EVP_CIPHER_CTX * ctx, ASN1_TYPE * params)
BLOCK_CIPHER_func_ecb(gost2814789, Gost2814789, EVP_GOST2814789_CTX, ks)
BLOCK_CIPHER_func_cfb(gost2814789, Gost2814789, 64, EVP_GOST2814789_CTX, ks)
-static int gost2814789_cnt_cipher(EVP_CIPHER_CTX * ctx, unsigned char *out,
- const unsigned char *in, size_t inl)
+static int
+gost2814789_cnt_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
+ const unsigned char *in, size_t inl)
{
EVP_GOST2814789_CTX *c = ctx->cipher_data;
while (inl >= EVP_MAXCHUNK) {
Gost2814789_cnt_encrypt(in, out, (long)EVP_MAXCHUNK, &c->ks,
- ctx->iv, ctx->buf, &ctx->num);
+ ctx->iv, ctx->buf, &ctx->num);
inl -= EVP_MAXCHUNK;
in += EVP_MAXCHUNK;
out += EVP_MAXCHUNK;
}
if (inl)
- Gost2814789_cnt_encrypt(in, out, inl, &c->ks,
- ctx->iv, ctx->buf, &ctx->num);
+ Gost2814789_cnt_encrypt(in, out, inl, &c->ks, ctx->iv, ctx->buf,
+ &ctx->num);
return 1;
}
diff --git a/lib/libssl/src/crypto/evp/m_gost2814789.c b/lib/libssl/src/crypto/evp/m_gost2814789.c
index ff3f489e464..279af872e02 100644
--- a/lib/libssl/src/crypto/evp/m_gost2814789.c
+++ b/lib/libssl/src/crypto/evp/m_gost2814789.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: m_gost2814789.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */
+/* $OpenBSD: m_gost2814789.c,v 1.2 2014/11/09 23:06:50 miod Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -56,22 +56,27 @@
#include <openssl/gost.h>
#include <openssl/objects.h>
-static int init(EVP_MD_CTX *ctx)
+static int
+gost2814789_init(EVP_MD_CTX *ctx)
{
- return GOST2814789IMIT_Init(ctx->md_data, NID_id_Gost28147_89_CryptoPro_A_ParamSet);
+ return GOST2814789IMIT_Init(ctx->md_data,
+ NID_id_Gost28147_89_CryptoPro_A_ParamSet);
}
-static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
+static int
+gost2814789_update(EVP_MD_CTX *ctx, const void *data, size_t count)
{
return GOST2814789IMIT_Update(ctx->md_data, data, count);
}
-static int final(EVP_MD_CTX *ctx, unsigned char *md)
+static int
+gost2814789_final(EVP_MD_CTX *ctx, unsigned char *md)
{
return GOST2814789IMIT_Final(md, ctx->md_data);
}
-static int md_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2)
+static int
+gost2814789_md_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2)
{
GOST2814789IMIT_CTX *gctx = ctx->md_data;
@@ -89,12 +94,12 @@ static const EVP_MD gost2814789imit_md = {
.pkey_type = NID_undef,
.md_size = GOST2814789IMIT_LENGTH,
.flags = 0,
- .init = init,
- .update = update,
- .final = final,
+ .init = gost2814789_init,
+ .update = gost2814789_update,
+ .final = gost2814789_final,
.block_size = GOST2814789IMIT_CBLOCK,
.ctx_size = sizeof(EVP_MD *) + sizeof(GOST2814789IMIT_CTX),
- .md_ctrl = md_ctrl,
+ .md_ctrl = gost2814789_md_ctrl,
};
const EVP_MD *
diff --git a/lib/libssl/src/crypto/evp/m_gostr341194.c b/lib/libssl/src/crypto/evp/m_gostr341194.c
index 380d92d5086..66d9b4f303e 100644
--- a/lib/libssl/src/crypto/evp/m_gostr341194.c
+++ b/lib/libssl/src/crypto/evp/m_gostr341194.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: m_gostr341194.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */
+/* $OpenBSD: m_gostr341194.c,v 1.2 2014/11/09 23:06:50 miod Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -58,17 +58,21 @@
#include <openssl/gost.h>
#include <openssl/objects.h>
-static int init(EVP_MD_CTX *ctx)
+static int
+gostr341194_init(EVP_MD_CTX *ctx)
{
- return GOSTR341194_Init(ctx->md_data, NID_id_GostR3411_94_CryptoProParamSet);
+ return GOSTR341194_Init(ctx->md_data,
+ NID_id_GostR3411_94_CryptoProParamSet);
}
-static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
+static int
+gostr341194_update(EVP_MD_CTX *ctx, const void *data, size_t count)
{
return GOSTR341194_Update(ctx->md_data, data, count);
}
-static int final(EVP_MD_CTX *ctx, unsigned char *md)
+static int
+gostr341194_final(EVP_MD_CTX *ctx, unsigned char *md)
{
return GOSTR341194_Final(md, ctx->md_data);
}
@@ -78,9 +82,9 @@ static const EVP_MD gostr341194_md = {
.pkey_type = NID_undef,
.md_size = GOSTR341194_LENGTH,
.flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE,
- .init = init,
- .update = update,
- .final = final,
+ .init = gostr341194_init,
+ .update = gostr341194_update,
+ .final = gostr341194_final,
.block_size = GOSTR341194_CBLOCK,
.ctx_size = sizeof(EVP_MD *) + sizeof(GOSTR341194_CTX),
};
diff --git a/lib/libssl/src/crypto/evp/m_streebog.c b/lib/libssl/src/crypto/evp/m_streebog.c
index cf4b159f439..882c7852bb7 100644
--- a/lib/libssl/src/crypto/evp/m_streebog.c
+++ b/lib/libssl/src/crypto/evp/m_streebog.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: m_streebog.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */
+/* $OpenBSD: m_streebog.c,v 1.2 2014/11/09 23:06:50 miod Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -57,32 +57,38 @@
#include <openssl/gost.h>
#include <openssl/objects.h>
-static int init256(EVP_MD_CTX *ctx)
+static int
+streebog_init256(EVP_MD_CTX *ctx)
{
return STREEBOG256_Init(ctx->md_data);
}
-static int update256(EVP_MD_CTX *ctx, const void *data, size_t count)
+static int
+streebog_update256(EVP_MD_CTX *ctx, const void *data, size_t count)
{
return STREEBOG256_Update(ctx->md_data, data, count);
}
-static int final256(EVP_MD_CTX *ctx, unsigned char *md)
+static int
+streebog_final256(EVP_MD_CTX *ctx, unsigned char *md)
{
return STREEBOG256_Final(md, ctx->md_data);
}
-static int init512(EVP_MD_CTX *ctx)
+static int
+streebog_init512(EVP_MD_CTX *ctx)
{
return STREEBOG512_Init(ctx->md_data);
}
-static int update512(EVP_MD_CTX *ctx, const void *data, size_t count)
+static int
+streebog_update512(EVP_MD_CTX *ctx, const void *data, size_t count)
{
return STREEBOG512_Update(ctx->md_data, data, count);
}
-static int final512(EVP_MD_CTX *ctx, unsigned char *md)
+static int
+streebog_final512(EVP_MD_CTX *ctx, unsigned char *md)
{
return STREEBOG512_Final(md, ctx->md_data);
}
@@ -92,9 +98,9 @@ static const EVP_MD streebog256_md = {
.pkey_type = NID_undef,
.md_size = STREEBOG256_LENGTH,
.flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE,
- .init = init256,
- .update = update256,
- .final = final256,
+ .init = streebog_init256,
+ .update = streebog_update256,
+ .final = streebog_final256,
.block_size = STREEBOG_CBLOCK,
.ctx_size = sizeof(EVP_MD *) + sizeof(STREEBOG_CTX),
};
@@ -104,9 +110,9 @@ static const EVP_MD streebog512_md = {
.pkey_type = NID_undef,
.md_size = STREEBOG512_LENGTH,
.flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE,
- .init = init512,
- .update = update512,
- .final = final512,
+ .init = streebog_init512,
+ .update = streebog_update512,
+ .final = streebog_final512,
.block_size = STREEBOG_CBLOCK,
.ctx_size = sizeof(EVP_MD *) + sizeof(STREEBOG_CTX),
};
diff --git a/lib/libssl/src/crypto/gost/gost2814789.c b/lib/libssl/src/crypto/gost/gost2814789.c
index b80f692f10c..1c11ddd93eb 100644
--- a/lib/libssl/src/crypto/gost/gost2814789.c
+++ b/lib/libssl/src/crypto/gost/gost2814789.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gost2814789.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */
+/* $OpenBSD: gost2814789.c,v 1.2 2014/11/09 23:06:52 miod Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -59,16 +59,19 @@
#include "gost_locl.h"
-static inline unsigned int f(const GOST2814789_KEY *c, unsigned int x)
+static inline unsigned int
+f(const GOST2814789_KEY *c, unsigned int x)
{
return c->k87[(x>>24) & 255] | c->k65[(x>>16) & 255]|
c->k43[(x>> 8) & 255] | c->k21[(x ) & 255];
}
-void Gost2814789_encrypt(const unsigned char *in, unsigned char *out,
- const GOST2814789_KEY *key)
+void
+Gost2814789_encrypt(const unsigned char *in, unsigned char *out,
+ const GOST2814789_KEY *key)
{
unsigned int n1, n2; /* As named in the GOST */
+
c2l(in, n1);
c2l(in, n2);
@@ -97,10 +100,12 @@ void Gost2814789_encrypt(const unsigned char *in, unsigned char *out,
l2c(n1, out);
}
-void Gost2814789_decrypt(const unsigned char *in, unsigned char *out,
- const GOST2814789_KEY *key)
+void
+Gost2814789_decrypt(const unsigned char *in, unsigned char *out,
+ const GOST2814789_KEY *key)
{
unsigned int n1, n2; /* As named in the GOST */
+
c2l(in, n1);
c2l(in, n2);
@@ -129,9 +134,9 @@ void Gost2814789_decrypt(const unsigned char *in, unsigned char *out,
l2c(n1, out);
}
-static void Gost2814789_mac(const unsigned char *in,
- unsigned char *mac,
- GOST2814789_KEY *key)
+static void
+Gost2814789_mac(const unsigned char *in, unsigned char *mac,
+ GOST2814789_KEY *key)
{
unsigned int n1, n2; /* As named in the GOST */
unsigned char *p;
@@ -160,9 +165,9 @@ static void Gost2814789_mac(const unsigned char *in,
l2c(n2, p);
}
-
-void Gost2814789_ecb_encrypt(const unsigned char *in, unsigned char *out,
- GOST2814789_KEY *key, const int enc)
+void
+Gost2814789_ecb_encrypt(const unsigned char *in, unsigned char *out,
+ GOST2814789_KEY *key, const int enc)
{
if (key->key_meshing && key->count == 1024) {
Gost2814789_cryptopro_key_mesh(key);
@@ -175,7 +180,8 @@ void Gost2814789_ecb_encrypt(const unsigned char *in, unsigned char *out,
Gost2814789_decrypt(in, out, key);
}
-static inline void Gost2814789_encrypt_mesh(unsigned char *iv, GOST2814789_KEY *key)
+static inline void
+Gost2814789_encrypt_mesh(unsigned char *iv, GOST2814789_KEY *key)
{
if (key->key_meshing && key->count == 1024) {
Gost2814789_cryptopro_key_mesh(key);
@@ -186,9 +192,9 @@ static inline void Gost2814789_encrypt_mesh(unsigned char *iv, GOST2814789_KEY *
key->count += 8;
}
-static inline void Gost2814789_mac_mesh(const unsigned char *data,
- unsigned char *mac,
- GOST2814789_KEY *key)
+static inline void
+Gost2814789_mac_mesh(const unsigned char *data, unsigned char *mac,
+ GOST2814789_KEY *key)
{
if (key->key_meshing && key->count == 1024) {
Gost2814789_cryptopro_key_mesh(key);
@@ -198,115 +204,125 @@ static inline void Gost2814789_mac_mesh(const unsigned char *data,
key->count += 8;
}
-void Gost2814789_cfb64_encrypt(const unsigned char *in, unsigned char *out,
- size_t len, GOST2814789_KEY *key,
- unsigned char *ivec, int *num, const int enc)
+void
+Gost2814789_cfb64_encrypt(const unsigned char *in, unsigned char *out,
+ size_t len, GOST2814789_KEY *key, unsigned char *ivec, int *num,
+ const int enc)
{
- unsigned int n;
- size_t l = 0;
+ unsigned int n;
+ size_t l = 0;
- OPENSSL_assert(in && out && key && ivec && num);
+ OPENSSL_assert(in && out && key && ivec && num);
- n = *num;
+ n = *num;
- if (enc) {
+ if (enc) {
#if !defined(OPENSSL_SMALL_FOOTPRINT)
- if (8%sizeof(size_t) == 0) do { /* always true actually */
- while (n && len) {
- *(out++) = ivec[n] ^= *(in++);
- --len;
- n = (n+1) % 8;
- }
+ if (8 % sizeof(size_t) == 0) do { /* always true actually */
+ while (n && len) {
+ *(out++) = ivec[n] ^= *(in++);
+ --len;
+ n = (n + 1) % 8;
+ }
#ifdef __STRICT_ALIGNMENT
- if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0)
- break;
+ if (((size_t)in | (size_t)out | (size_t)ivec) %
+ sizeof(size_t) != 0)
+ break;
#endif
- while (len>=8) {
- Gost2814789_encrypt_mesh(ivec, key);
- for (; n<8; n+=sizeof(size_t)) {
- *(size_t*)(out+n) =
- *(size_t*)(ivec+n) ^= *(size_t*)(in+n);
+ while (len >= 8) {
+ Gost2814789_encrypt_mesh(ivec, key);
+ for (; n < 8; n += sizeof(size_t)) {
+ *(size_t*)(out + n) =
+ *(size_t*)(ivec + n) ^=
+ *(size_t*)(in + n);
+ }
+ len -= 8;
+ out += 8;
+ in += 8;
+ n = 0;
}
- len -= 8;
- out += 8;
- in += 8;
- n = 0;
- }
- if (len) {
- Gost2814789_encrypt_mesh(ivec, key);
- while (len--) {
- out[n] = ivec[n] ^= in[n];
- ++n;
+ if (len) {
+ Gost2814789_encrypt_mesh(ivec, key);
+ while (len--) {
+ out[n] = ivec[n] ^= in[n];
+ ++n;
+ }
}
- }
- *num = n;
- return;
- } while (0);
- /* the rest would be commonly eliminated by x86* compiler */
+ *num = n;
+ return;
+ } while (0);
+ /* the rest would be commonly eliminated by x86* compiler */
#endif
- while (l<len) {
- if (n == 0) {
- Gost2814789_encrypt_mesh(ivec, key);
+ while (l<len) {
+ if (n == 0) {
+ Gost2814789_encrypt_mesh(ivec, key);
+ }
+ out[l] = ivec[n] ^= in[l];
+ ++l;
+ n = (n + 1) % 8;
}
- out[l] = ivec[n] ^= in[l];
- ++l;
- n = (n+1) % 8;
- }
- *num = n;
- } else {
+ *num = n;
+ } else {
#if !defined(OPENSSL_SMALL_FOOTPRINT)
- if (8%sizeof(size_t) == 0) do { /* always true actually */
- while (n && len) {
- unsigned char c;
- *(out++) = ivec[n] ^ (c = *(in++)); ivec[n] = c;
- --len;
- n = (n+1) % 8;
- }
+ if (8 % sizeof(size_t) == 0) do { /* always true actually */
+ while (n && len) {
+ unsigned char c;
+
+ *(out++) = ivec[n] ^ (c = *(in++));
+ ivec[n] = c;
+ --len;
+ n = (n + 1) % 8;
+ }
#ifdef __STRICT_ALIGNMENT
- if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0)
- break;
+ if (((size_t)in | (size_t)out | (size_t)ivec) %
+ sizeof(size_t) != 0)
+ break;
#endif
- while (len>=8) {
- Gost2814789_encrypt_mesh(ivec, key);
- for (; n<8; n+=sizeof(size_t)) {
- size_t t = *(size_t*)(in+n);
- *(size_t*)(out+n) = *(size_t*)(ivec+n) ^ t;
- *(size_t*)(ivec+n) = t;
- }
- len -= 8;
- out += 8;
- in += 8;
- n = 0;
- }
- if (len) {
- Gost2814789_encrypt_mesh(ivec, key);
- while (len--) {
- unsigned char c;
- out[n] = ivec[n] ^ (c = in[n]); ivec[n] = c;
- ++n;
+ while (len >= 8) {
+ Gost2814789_encrypt_mesh(ivec, key);
+ for (; n < 8; n += sizeof(size_t)) {
+ size_t t = *(size_t*)(in + n);
+ *(size_t*)(out + n) =
+ *(size_t*)(ivec + n) ^ t;
+ *(size_t*)(ivec + n) = t;
+ }
+ len -= 8;
+ out += 8;
+ in += 8;
+ n = 0;
}
- }
- *num = n;
- return;
- } while (0);
- /* the rest would be commonly eliminated by x86* compiler */
+ if (len) {
+ Gost2814789_encrypt_mesh(ivec, key);
+ while (len--) {
+ unsigned char c;
+
+ out[n] = ivec[n] ^ (c = in[n]);
+ ivec[n] = c;
+ ++n;
+ }
+ }
+ *num = n;
+ return;
+ } while (0);
+ /* the rest would be commonly eliminated by x86* compiler */
#endif
- while (l<len) {
- unsigned char c;
- if (n == 0) {
- Gost2814789_encrypt_mesh(ivec, key);
+ while (l < len) {
+ unsigned char c;
+
+ if (n == 0) {
+ Gost2814789_encrypt_mesh(ivec, key);
+ }
+ out[l] = ivec[n] ^ (c = in[l]); ivec[n] = c;
+ ++l;
+ n = (n + 1) % 8;
}
- out[l] = ivec[n] ^ (c = in[l]); ivec[n] = c;
- ++l;
- n = (n+1) % 8;
+ *num = n;
}
- *num=n;
- }
}
-static inline void Gost2814789_cnt_next(unsigned char *ivec,
- unsigned char *out,
- GOST2814789_KEY *key)
+static inline void
+Gost2814789_cnt_next(unsigned char *ivec, unsigned char *out,
+ GOST2814789_KEY *key)
{
unsigned char *p = ivec, *p2 = ivec;
unsigned int val, val2;
@@ -334,34 +350,35 @@ static inline void Gost2814789_cnt_next(unsigned char *ivec,
key->count += 8;
}
-void Gost2814789_cnt_encrypt(const unsigned char *in, unsigned char *out,
- size_t len, GOST2814789_KEY *key,
- unsigned char *ivec, unsigned char *cnt_buf, int *num)
+void
+Gost2814789_cnt_encrypt(const unsigned char *in, unsigned char *out, size_t len,
+ GOST2814789_KEY *key, unsigned char *ivec, unsigned char *cnt_buf, int *num)
{
unsigned int n;
- size_t l=0;
+ size_t l = 0;
OPENSSL_assert(in && out && key && cnt_buf && num);
n = *num;
#if !defined(OPENSSL_SMALL_FOOTPRINT)
- if (8%sizeof(size_t) == 0) do { /* always true actually */
+ if (8 % sizeof(size_t) == 0) do { /* always true actually */
while (n && len) {
*(out++) = *(in++) ^ cnt_buf[n];
--len;
- n = (n+1) % 8;
+ n = (n + 1) % 8;
}
#ifdef __STRICT_ALIGNMENT
- if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0)
+ if (((size_t)in | (size_t)out | (size_t)ivec) %
+ sizeof(size_t) != 0)
break;
#endif
- while (len>=8) {
+ while (len >= 8) {
Gost2814789_cnt_next(ivec, cnt_buf, key);
- for (; n<8; n+=sizeof(size_t))
- *(size_t *)(out+n) =
- *(size_t *)(in+n) ^ *(size_t *)(cnt_buf+n);
+ for (; n < 8; n += sizeof(size_t))
+ *(size_t *)(out + n) = *(size_t *)(in + n) ^
+ *(size_t *)(cnt_buf + n);
len -= 8;
out += 8;
in += 8;
@@ -379,27 +396,31 @@ void Gost2814789_cnt_encrypt(const unsigned char *in, unsigned char *out,
} while(0);
/* the rest would be commonly eliminated by x86* compiler */
#endif
- while (l<len) {
+ while (l < len) {
if (n==0)
Gost2814789_cnt_next(ivec, cnt_buf, key);
out[l] = in[l] ^ cnt_buf[n];
++l;
- n = (n+1) % 8;
+ n = (n + 1) % 8;
}
*num=n;
}
-int GOST2814789IMIT_Init(GOST2814789IMIT_CTX *c, int nid)
+int
+GOST2814789IMIT_Init(GOST2814789IMIT_CTX *c, int nid)
{
c->Nl = c->Nh = c->num = 0;
memset(c->mac, 0, 8);
return Gost2814789_set_sbox(&c->cipher, nid);
}
-static void GOST2814789IMIT_block_data_order(GOST2814789IMIT_CTX *ctx, const void *p, size_t num)
+static void
+GOST2814789IMIT_block_data_order(GOST2814789IMIT_CTX *ctx, const void *p,
+ size_t num)
{
int i;
+
for (i = 0; i < num; i++) {
Gost2814789_mac_mesh(p, ctx->mac, &ctx->cipher);
p += 8;
@@ -418,7 +439,8 @@ static void GOST2814789IMIT_block_data_order(GOST2814789IMIT_CTX *ctx, const voi
#include "md32_common.h"
-int GOST2814789IMIT_Final(unsigned char *md, GOST2814789IMIT_CTX *c)
+int
+GOST2814789IMIT_Final(unsigned char *md, GOST2814789IMIT_CTX *c)
{
if (c->num) {
memset(c->data + c->num, 0, 8 - c->num);
@@ -432,9 +454,9 @@ int GOST2814789IMIT_Final(unsigned char *md, GOST2814789IMIT_CTX *c)
return 1;
}
-unsigned char *GOST2814789IMIT(const unsigned char *d, size_t n,
- unsigned char *md, int nid,
- const unsigned char *key, const unsigned char *iv)
+unsigned char *
+GOST2814789IMIT(const unsigned char *d, size_t n, unsigned char *md, int nid,
+ const unsigned char *key, const unsigned char *iv)
{
GOST2814789IMIT_CTX c;
static unsigned char m[GOST2814789IMIT_LENGTH];
diff --git a/lib/libssl/src/crypto/gost/gost89_params.c b/lib/libssl/src/crypto/gost/gost89_params.c
index 2b2607d24ba..35d8f62fe96 100644
--- a/lib/libssl/src/crypto/gost/gost89_params.c
+++ b/lib/libssl/src/crypto/gost/gost89_params.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gost89_params.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */
+/* $OpenBSD: gost89_params.c,v 1.2 2014/11/09 23:06:52 miod Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -179,7 +179,8 @@ static const struct gost89_parameters_info {
{NID_undef,NULL,0}
};
-int Gost2814789_set_sbox(GOST2814789_KEY *key, int nid)
+int
+Gost2814789_set_sbox(GOST2814789_KEY *key, int nid)
{
int i;
const gost_subst_block *b = NULL;
@@ -194,7 +195,7 @@ int Gost2814789_set_sbox(GOST2814789_KEY *key, int nid)
break;
}
- if (!b)
+ if (b == NULL)
return 0;
for (i = 0; i < 256; i++) {
@@ -211,8 +212,9 @@ int Gost2814789_set_sbox(GOST2814789_KEY *key, int nid)
return 1;
}
-int Gost2814789_set_key(GOST2814789_KEY *key,
- const unsigned char *userKey, const int bits)
+int
+Gost2814789_set_key(GOST2814789_KEY *key, const unsigned char *userKey,
+ const int bits)
{
int i;
@@ -227,7 +229,8 @@ int Gost2814789_set_key(GOST2814789_KEY *key,
return 1;
}
-void Gost2814789_cryptopro_key_mesh(GOST2814789_KEY *key)
+void
+Gost2814789_cryptopro_key_mesh(GOST2814789_KEY *key)
{
unsigned char newkey[32];
diff --git a/lib/libssl/src/crypto/gost/gost89imit_ameth.c b/lib/libssl/src/crypto/gost/gost89imit_ameth.c
index 879c2b0ca0d..a2631d97f8a 100644
--- a/lib/libssl/src/crypto/gost/gost89imit_ameth.c
+++ b/lib/libssl/src/crypto/gost/gost89imit_ameth.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gost89imit_ameth.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */
+/* $OpenBSD: gost89imit_ameth.c,v 1.2 2014/11/09 23:06:52 miod Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -56,14 +56,14 @@
#include "asn1_locl.h"
-static void mackey_free_gost(EVP_PKEY *pk)
+static void
+mackey_free_gost(EVP_PKEY *pk)
{
- if (pk->pkey.ptr) {
- free(pk->pkey.ptr);
- }
+ free(pk->pkey.ptr);
}
-static int mac_ctrl_gost(EVP_PKEY *pkey, int op, long arg1, void *arg2)
+static int
+mac_ctrl_gost(EVP_PKEY *pkey, int op, long arg1, void *arg2)
{
switch (op) {
case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
diff --git a/lib/libssl/src/crypto/gost/gost89imit_pmeth.c b/lib/libssl/src/crypto/gost/gost89imit_pmeth.c
index ec9c72372c2..fa79abf0afc 100644
--- a/lib/libssl/src/crypto/gost/gost89imit_pmeth.c
+++ b/lib/libssl/src/crypto/gost/gost89imit_pmeth.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gost89imit_pmeth.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */
+/* $OpenBSD: gost89imit_pmeth.c,v 1.2 2014/11/09 23:06:52 miod Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -57,7 +57,7 @@
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/gost.h>
-#include <openssl/x509v3.h> /*For string_to_hex */
+#include <openssl/x509v3.h> /* For string_to_hex */
#include "evp_locl.h"
#include "gost_locl.h"
@@ -65,31 +65,34 @@
struct gost_mac_pmeth_data {
EVP_MD *md;
unsigned char key[32];
- unsigned key_set : 1;
+ unsigned key_set :1;
};
-static int pkey_gost_mac_init(EVP_PKEY_CTX *ctx)
+static int
+pkey_gost_mac_init(EVP_PKEY_CTX *ctx)
{
struct gost_mac_pmeth_data *data;
data = calloc(1, sizeof(struct gost_mac_pmeth_data));
- if (!data)
+ if (data == NULL)
return 0;
- EVP_PKEY_CTX_set_data(ctx,data);
+ EVP_PKEY_CTX_set_data(ctx, data);
return 1;
}
-static void pkey_gost_mac_cleanup (EVP_PKEY_CTX *ctx)
+static void
+pkey_gost_mac_cleanup(EVP_PKEY_CTX *ctx)
{
struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
free(data);
}
-static int pkey_gost_mac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
+static int
+pkey_gost_mac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
{
struct gost_mac_pmeth_data *dst_data, *src_data;
- if (!pkey_gost_mac_init(dst))
+ if (pkey_gost_mac_init(dst) == 0)
return 0;
src_data = EVP_PKEY_CTX_get_data(src);
@@ -100,7 +103,8 @@ static int pkey_gost_mac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
return 1;
}
-static int pkey_gost_mac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
+static int
+pkey_gost_mac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
{
struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
unsigned char *keydata;
@@ -132,7 +136,8 @@ static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
case EVP_PKEY_CTRL_SET_MAC_KEY:
if (p1 != 32) {
- GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_INVALID_MAC_KEY_LENGTH);
+ GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,
+ GOST_R_INVALID_MAC_KEY_LENGTH);
return 0;
}
@@ -141,67 +146,78 @@ static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
return 1;
case EVP_PKEY_CTRL_DIGESTINIT:
- {
- EVP_MD_CTX *mctx = p2;
- void *key;
- if (!data->key_set) {
- EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
- if (!pkey) {
- GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_MAC_KEY_NOT_SET);
- return 0;
- }
- key = EVP_PKEY_get0(pkey);
- if (!key) {
- GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_MAC_KEY_NOT_SET);
- return 0;
- }
- } else {
- key = &(data->key);
+ {
+ EVP_MD_CTX *mctx = p2;
+ void *key;
+
+ if (!data->key_set) {
+ EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
+ if (pkey == NULL) {
+ GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,
+ GOST_R_MAC_KEY_NOT_SET);
+ return 0;
}
- if (!mctx->digest->md_ctrl)
+ key = EVP_PKEY_get0(pkey);
+ if (key == NULL) {
+ GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,
+ GOST_R_MAC_KEY_NOT_SET);
return 0;
- return mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_SET_KEY, 32 * 8, key);
+ }
+ } else {
+ key = &(data->key);
}
+ if (mctx->digest->md_ctrl == NULL)
+ return 0;
+ return mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_SET_KEY, 32 * 8,
+ key);
+ }
}
return -2;
}
-static int pkey_gost_mac_ctrl_str(EVP_PKEY_CTX *ctx,
- const char *type, const char *value)
+
+static int
+pkey_gost_mac_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value)
{
- if (!value)
+ if (value == NULL)
return 0;
- if (!strcmp(type, "key")) {
+ if (strcmp(type, "key") == 0) {
void *p = (void *)value;
- return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, strlen(value), p);
+ return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY,
+ strlen(value), p);
}
- if (!strcmp(type, "hexkey")) {
+ if (strcmp(type, "hexkey") == 0) {
unsigned char *key;
int r;
long keylen;
+
key = string_to_hex(value, &keylen);
- if (!key)
+ if (key == NULL)
return 0;
- r = pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, keylen, key);
+ r = pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, keylen,
+ key);
free(key);
return r;
}
return -2;
}
-static int pkey_gost_mac_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)
+static int
+pkey_gost_mac_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)
{
return 1;
}
-static int pkey_gost_mac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, EVP_MD_CTX *mctx)
+static int
+pkey_gost_mac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
+ EVP_MD_CTX *mctx)
{
- unsigned int tmpsiglen=*siglen; /* for platforms where sizeof(int)!=sizeof(size_t)*/
+ /* for platforms where sizeof(int) != sizeof(size_t)*/
+ unsigned int tmpsiglen = *siglen;
int ret;
-
- if (!sig) {
+ if (sig == NULL) {
*siglen = 4;
return 1;
}
diff --git a/lib/libssl/src/crypto/gost/gostr341001_ameth.c b/lib/libssl/src/crypto/gost/gostr341001_ameth.c
index 09b851cef4f..710f2aa58c6 100644
--- a/lib/libssl/src/crypto/gost/gostr341001_ameth.c
+++ b/lib/libssl/src/crypto/gost/gostr341001_ameth.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gostr341001_ameth.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */
+/* $OpenBSD: gostr341001_ameth.c,v 1.2 2014/11/09 23:06:52 miod Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -68,15 +68,18 @@
#include "gost_locl.h"
#include "gost_asn1.h"
-static void pkey_free_gost01(EVP_PKEY *key)
+static void
+pkey_free_gost01(EVP_PKEY *key)
{
GOST_KEY_free(key->pkey.gost);
}
-/* Parses GOST algorithm parameters from X509_ALGOR and
+/*
+ * Parses GOST algorithm parameters from X509_ALGOR and
* modifies pkey setting NID and parameters
*/
-static int decode_gost01_algor_params(EVP_PKEY * pkey, const unsigned char **p, int len)
+static int
+decode_gost01_algor_params(EVP_PKEY *pkey, const unsigned char **p, int len)
{
int param_nid = NID_undef, digest_nid = NID_undef;
GOST_KEY_PARAMS *gkp = NULL;
@@ -84,7 +87,7 @@ static int decode_gost01_algor_params(EVP_PKEY * pkey, const unsigned char **p,
GOST_KEY *ec;
gkp = d2i_GOST_KEY_PARAMS(NULL, p, len);
- if (!gkp) {
+ if (gkp == NULL) {
GOSTerr(GOST_F_DECODE_GOST01_ALGOR_PARAMS,
GOST_R_BAD_PKEY_PARAMETERS_FORMAT);
return 0;
@@ -92,10 +95,13 @@ static int decode_gost01_algor_params(EVP_PKEY * pkey, const unsigned char **p,
param_nid = OBJ_obj2nid(gkp->key_params);
digest_nid = OBJ_obj2nid(gkp->hash_params);
GOST_KEY_PARAMS_free(gkp);
+
ec = pkey->pkey.gost;
- if (!ec) {
+ if (ec == NULL) {
ec = GOST_KEY_new();
- if (!EVP_PKEY_assign_GOST(pkey, ec))
+ if (ec == NULL)
+ return 0;
+ if (EVP_PKEY_assign_GOST(pkey, ec) == 0)
return 0;
}
@@ -113,26 +119,30 @@ static int decode_gost01_algor_params(EVP_PKEY * pkey, const unsigned char **p,
return 1;
}
-static ASN1_STRING *encode_gost01_algor_params(const EVP_PKEY * key)
+static ASN1_STRING *
+encode_gost01_algor_params(const EVP_PKEY *key)
{
ASN1_STRING *params = ASN1_STRING_new();
GOST_KEY_PARAMS *gkp = GOST_KEY_PARAMS_new();
int pkey_param_nid = NID_undef;
- if (!params || !gkp) {
- GOSTerr(GOST_F_ENCODE_GOST01_ALGOR_PARAMS, ERR_R_MALLOC_FAILURE);
+ if (params == NULL || gkp == NULL) {
+ GOSTerr(GOST_F_ENCODE_GOST01_ALGOR_PARAMS,
+ ERR_R_MALLOC_FAILURE);
ASN1_STRING_free(params);
params = NULL;
goto err;
}
- pkey_param_nid = EC_GROUP_get_curve_name(GOST_KEY_get0_group(key->pkey.gost));
+ pkey_param_nid =
+ EC_GROUP_get_curve_name(GOST_KEY_get0_group(key->pkey.gost));
gkp->key_params = OBJ_nid2obj(pkey_param_nid);
gkp->hash_params = OBJ_nid2obj(GOST_KEY_get_digest(key->pkey.gost));
/*gkp->cipher_params = OBJ_nid2obj(cipher_param_nid); */
params->length = i2d_GOST_KEY_PARAMS(gkp, &params->data);
if (params->length <= 0) {
- GOSTerr(GOST_F_ENCODE_GOST01_ALGOR_PARAMS, ERR_R_MALLOC_FAILURE);
+ GOSTerr(GOST_F_ENCODE_GOST01_ALGOR_PARAMS,
+ ERR_R_MALLOC_FAILURE);
ASN1_STRING_free(params);
params = NULL;
goto err;
@@ -143,37 +153,42 @@ err:
return params;
}
-static int pub_cmp_gost01(const EVP_PKEY * a, const EVP_PKEY * b)
+static int
+pub_cmp_gost01(const EVP_PKEY *a, const EVP_PKEY *b)
{
const GOST_KEY *ea = a->pkey.gost;
const GOST_KEY *eb = b->pkey.gost;
const EC_POINT *ka, *kb;
int ret = 0;
- if (!ea || !eb)
+
+ if (ea == NULL || eb == NULL)
return 0;
ka = GOST_KEY_get0_public_key(ea);
kb = GOST_KEY_get0_public_key(eb);
- if (!ka || !kb)
+ if (ka == NULL || kb == NULL)
return 0;
ret = (0 == EC_POINT_cmp(GOST_KEY_get0_group(ea), ka, kb, NULL));
return ret;
}
-static int pkey_size_gost01(const EVP_PKEY * pk)
+static int
+pkey_size_gost01(const EVP_PKEY *pk)
{
if (GOST_KEY_get_digest(pk->pkey.gost) == NID_id_tc26_gost3411_2012_512)
return 128;
return 64;
}
-static int pkey_bits_gost01(const EVP_PKEY * pk)
+static int
+pkey_bits_gost01(const EVP_PKEY *pk)
{
if (GOST_KEY_get_digest(pk->pkey.gost) == NID_id_tc26_gost3411_2012_512)
return 512;
return 256;
}
-static int pub_decode_gost01(EVP_PKEY *pk, X509_PUBKEY *pub)
+static int
+pub_decode_gost01(EVP_PKEY *pk, X509_PUBKEY *pub)
{
X509_ALGOR *palg = NULL;
const unsigned char *pubkey_buf = NULL;
@@ -187,21 +202,22 @@ static int pub_decode_gost01(EVP_PKEY *pk, X509_PUBKEY *pub)
int ptype = V_ASN1_UNDEF;
ASN1_STRING *pval = NULL;
- if (!X509_PUBKEY_get0_param(&palgobj, &pubkey_buf, &pub_len,
- &palg, pub))
+ if (X509_PUBKEY_get0_param(&palgobj, &pubkey_buf, &pub_len, &palg, pub)
+ == 0)
return 0;
- EVP_PKEY_assign_GOST(pk, NULL);
+ (void)EVP_PKEY_assign_GOST(pk, NULL);
X509_ALGOR_get0(NULL, &ptype, (void **)&pval, palg);
if (ptype != V_ASN1_SEQUENCE) {
GOSTerr(GOST_F_PUB_DECODE_GOST01,
- GOST_R_BAD_KEY_PARAMETERS_FORMAT);
+ GOST_R_BAD_KEY_PARAMETERS_FORMAT);
return 0;
}
p = pval->data;
- if (!decode_gost01_algor_params(pk, &p, pval->length))
+ if (decode_gost01_algor_params(pk, &p, pval->length) == 0)
return 0;
+
octet = d2i_ASN1_OCTET_STRING(NULL, &pubkey_buf, pub_len);
- if (!octet) {
+ if (octet == NULL) {
GOSTerr(GOST_F_PUB_DECODE_GOST01, ERR_R_MALLOC_FAILURE);
return 0;
}
@@ -363,7 +379,8 @@ static int priv_print_gost01(BIO * out, const EVP_PKEY * pkey, int indent,
return pub_print_gost01(out, pkey, indent, pctx);
}
-static int priv_decode_gost01(EVP_PKEY * pk, PKCS8_PRIV_KEY_INFO * p8inf)
+static int
+priv_decode_gost01(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf)
{
const unsigned char *pkey_buf = NULL, *p = NULL;
int priv_len = 0;
@@ -376,25 +393,27 @@ static int priv_decode_gost01(EVP_PKEY * pk, PKCS8_PRIV_KEY_INFO * p8inf)
int ptype = V_ASN1_UNDEF;
ASN1_STRING *pval = NULL;
- if (!PKCS8_pkey_get0(&palg_obj, &pkey_buf, &priv_len, &palg, p8inf))
+ if (PKCS8_pkey_get0(&palg_obj, &pkey_buf, &priv_len, &palg, p8inf) == 0)
return 0;
- EVP_PKEY_assign_GOST(pk, NULL);
+ (void)EVP_PKEY_assign_GOST(pk, NULL);
X509_ALGOR_get0(NULL, &ptype, (void **)&pval, palg);
if (ptype != V_ASN1_SEQUENCE) {
GOSTerr(GOST_F_PUB_DECODE_GOST01,
- GOST_R_BAD_KEY_PARAMETERS_FORMAT);
+ GOST_R_BAD_KEY_PARAMETERS_FORMAT);
return 0;
}
p = pval->data;
- if (!decode_gost01_algor_params(pk, &p, pval->length))
+ if (decode_gost01_algor_params(pk, &p, pval->length) == 0)
return 0;
p = pkey_buf;
if (V_ASN1_OCTET_STRING == *p) {
/* New format - Little endian octet string */
unsigned char rev_buf[32];
int i;
- ASN1_OCTET_STRING *s = d2i_ASN1_OCTET_STRING(NULL, &p, priv_len);
- if (!s || s->length != 32) {
+ ASN1_OCTET_STRING *s =
+ d2i_ASN1_OCTET_STRING(NULL, &p, priv_len);
+
+ if (s == NULL || s->length != 32) {
GOSTerr(GOST_F_PRIV_DECODE_GOST01, EVP_R_DECODE_ERROR);
return 0;
}
@@ -483,13 +502,14 @@ static int param_decode_gost01(EVP_PKEY * pkey, const unsigned char **pder,
ASN1_OBJECT_free(obj);
ec = GOST_KEY_new();
- if (!ec) {
+ if (ec == NULL) {
GOSTerr(GOST_F_PARAM_DECODE_GOST01, ERR_R_MALLOC_FAILURE);
return 0;
}
group = EC_GROUP_new_by_curve_name(nid);
if (group == NULL) {
- GOSTerr(GOST_F_PARAM_DECODE_GOST01, EC_R_EC_GROUP_NEW_BY_NAME_FAILURE);
+ GOSTerr(GOST_F_PARAM_DECODE_GOST01,
+ EC_R_EC_GROUP_NEW_BY_NAME_FAILURE);
GOST_KEY_free(ec);
return 0;
}
@@ -602,10 +622,12 @@ static int pkey_ctrl_gost01(EVP_PKEY * pkey, int op, long arg1, void *arg2)
X509_ALGOR_set0(alg2, OBJ_nid2obj(GostR3410_get_pk_digest(digest)), V_ASN1_NULL, 0);
if (alg3) {
ASN1_STRING *params = encode_gost01_algor_params(pkey);
- if (!params) {
+ if (params == NULL) {
return -1;
}
- X509_ALGOR_set0(alg3, OBJ_nid2obj(GostR3410_get_pk_digest(digest)), V_ASN1_SEQUENCE, params);
+ X509_ALGOR_set0(alg3,
+ OBJ_nid2obj(GostR3410_get_pk_digest(digest)),
+ V_ASN1_SEQUENCE, params);
}
return 1;
diff --git a/lib/libssl/src/crypto/gost/gostr341001_key.c b/lib/libssl/src/crypto/gost/gostr341001_key.c
index 9c7f52b7696..b236dde28a9 100644
--- a/lib/libssl/src/crypto/gost/gostr341001_key.c
+++ b/lib/libssl/src/crypto/gost/gostr341001_key.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gostr341001_key.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */
+/* $OpenBSD: gostr341001_key.c,v 1.2 2014/11/09 23:06:52 miod Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -68,7 +68,8 @@ struct gost_key_st {
int digest_nid;
};
-GOST_KEY * GOST_KEY_new(void)
+GOST_KEY *
+GOST_KEY_new(void)
{
GOST_KEY *ret;
@@ -85,7 +86,8 @@ GOST_KEY * GOST_KEY_new(void)
return (ret);
}
-void GOST_KEY_free(GOST_KEY * r)
+void
+GOST_KEY_free(GOST_KEY *r)
{
int i;
@@ -100,23 +102,23 @@ void GOST_KEY_free(GOST_KEY * r)
EC_POINT_free(r->pub_key);
BN_clear_free(r->priv_key);
- OPENSSL_cleanse((void *) r, sizeof(GOST_KEY));
-
+ OPENSSL_cleanse((void *)r, sizeof(GOST_KEY));
free(r);
}
-int GOST_KEY_check_key(const GOST_KEY * key)
+int
+GOST_KEY_check_key(const GOST_KEY *key)
{
int ok = 0;
BN_CTX *ctx = NULL;
BIGNUM *order = NULL;
EC_POINT *point = NULL;
- if (!key || !key->group || !key->pub_key) {
+ if (key == NULL || key->group == NULL || key->pub_key == NULL) {
GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
- if (EC_POINT_is_at_infinity(key->group, key->pub_key)) {
+ if (EC_POINT_is_at_infinity(key->group, key->pub_key) != 0) {
GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_POINT_AT_INFINITY);
goto err;
}
@@ -126,22 +128,23 @@ int GOST_KEY_check_key(const GOST_KEY * key)
goto err;
/* testing whether the pub_key is on the elliptic curve */
- if (!EC_POINT_is_on_curve(key->group, key->pub_key, ctx)) {
+ if (EC_POINT_is_on_curve(key->group, key->pub_key, ctx) == 0) {
GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_POINT_IS_NOT_ON_CURVE);
goto err;
}
/* testing whether pub_key * order is the point at infinity */
if ((order = BN_new()) == NULL)
goto err;
- if (!EC_GROUP_get_order(key->group, order, ctx)) {
+ if (EC_GROUP_get_order(key->group, order, ctx) == 0) {
GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_INVALID_GROUP_ORDER);
goto err;
}
- if (!EC_POINT_mul(key->group, point, NULL, key->pub_key, order, ctx)) {
+ if (EC_POINT_mul(key->group, point, NULL, key->pub_key, order,
+ ctx) == 0) {
GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, ERR_R_EC_LIB);
goto err;
}
- if (!EC_POINT_is_at_infinity(key->group, point)) {
+ if (EC_POINT_is_at_infinity(key->group, point) == 0) {
GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_WRONG_ORDER);
goto err;
}
@@ -149,19 +152,19 @@ int GOST_KEY_check_key(const GOST_KEY * key)
* in case the priv_key is present : check if generator * priv_key ==
* pub_key
*/
- if (key->priv_key) {
+ if (key->priv_key != NULL) {
if (BN_cmp(key->priv_key, order) >= 0) {
GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_WRONG_ORDER);
goto err;
}
- if (!EC_POINT_mul(key->group, point, key->priv_key,
- NULL, NULL, ctx)) {
+ if (EC_POINT_mul(key->group, point, key->priv_key, NULL, NULL,
+ ctx) == 0) {
GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, ERR_R_EC_LIB);
goto err;
}
- if (EC_POINT_cmp(key->group, point, key->pub_key,
- ctx) != 0) {
- GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_INVALID_PRIVATE_KEY);
+ if (EC_POINT_cmp(key->group, point, key->pub_key, ctx) != 0) {
+ GOSTerr(GOST_F_GOST_KEY_CHECK_KEY,
+ EC_R_INVALID_PRIVATE_KEY);
goto err;
}
}
@@ -220,30 +223,34 @@ int GOST_KEY_set_public_key_affine_coordinates(GOST_KEY * key, BIGNUM * x, BIGNU
ok = 1;
err:
- BN_CTX_free(ctx);
EC_POINT_free(point);
+ BN_CTX_free(ctx);
return ok;
}
-const EC_GROUP * GOST_KEY_get0_group(const GOST_KEY * key)
+const EC_GROUP *
+GOST_KEY_get0_group(const GOST_KEY *key)
{
return key->group;
}
-int GOST_KEY_set_group(GOST_KEY * key, const EC_GROUP * group)
+int
+GOST_KEY_set_group(GOST_KEY *key, const EC_GROUP *group)
{
EC_GROUP_free(key->group);
key->group = EC_GROUP_dup(group);
return (key->group == NULL) ? 0 : 1;
}
-const BIGNUM * GOST_KEY_get0_private_key(const GOST_KEY * key)
+const BIGNUM *
+GOST_KEY_get0_private_key(const GOST_KEY *key)
{
return key->priv_key;
}
-int GOST_KEY_set_private_key(GOST_KEY * key, const BIGNUM * priv_key)
+int
+GOST_KEY_set_private_key(GOST_KEY *key, const BIGNUM *priv_key)
{
BN_clear_free(key->priv_key);
key->priv_key = BN_dup(priv_key);
@@ -251,23 +258,26 @@ int GOST_KEY_set_private_key(GOST_KEY * key, const BIGNUM * priv_key)
}
const EC_POINT *
-GOST_KEY_get0_public_key(const GOST_KEY * key)
+GOST_KEY_get0_public_key(const GOST_KEY *key)
{
return key->pub_key;
}
-int GOST_KEY_set_public_key(GOST_KEY * key, const EC_POINT * pub_key)
+int
+GOST_KEY_set_public_key(GOST_KEY *key, const EC_POINT *pub_key)
{
EC_POINT_free(key->pub_key);
key->pub_key = EC_POINT_dup(pub_key, key->group);
return (key->pub_key == NULL) ? 0 : 1;
}
-int GOST_KEY_get_digest(const GOST_KEY * key)
+int
+GOST_KEY_get_digest(const GOST_KEY *key)
{
return key->digest_nid;
}
-int GOST_KEY_set_digest(GOST_KEY * key, int digest_nid)
+int
+GOST_KEY_set_digest(GOST_KEY *key, int digest_nid)
{
if (digest_nid == NID_id_GostR3411_94_CryptoProParamSet ||
digest_nid == NID_id_tc26_gost3411_2012_256 ||
@@ -279,7 +289,8 @@ int GOST_KEY_set_digest(GOST_KEY * key, int digest_nid)
return 0;
}
-size_t GOST_KEY_get_size(const GOST_KEY * r)
+size_t
+GOST_KEY_get_size(const GOST_KEY *r)
{
int i;
BIGNUM *order = NULL;
@@ -294,7 +305,7 @@ size_t GOST_KEY_get_size(const GOST_KEY * r)
if ((order = BN_new()) == NULL)
return 0;
- if (!EC_GROUP_get_order(group,order,NULL)) {
+ if (EC_GROUP_get_order(group, order, NULL) == 0) {
BN_clear_free(order);
return 0;
}
diff --git a/lib/libssl/src/crypto/gost/gostr341001_params.c b/lib/libssl/src/crypto/gost/gostr341001_params.c
index 1c8276e7b06..d14097df7e6 100644
--- a/lib/libssl/src/crypto/gost/gostr341001_params.c
+++ b/lib/libssl/src/crypto/gost/gostr341001_params.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gostr341001_params.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */
+/* $OpenBSD: gostr341001_params.c,v 1.2 2014/11/09 23:06:52 miod Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -59,14 +59,16 @@
#include "gost_locl.h"
-int GostR3410_get_md_digest(int nid)
+int
+GostR3410_get_md_digest(int nid)
{
if (nid == NID_id_GostR3411_94_CryptoProParamSet)
return NID_id_GostR3411_94;
return nid;
}
-int GostR3410_get_pk_digest(int nid)
+int
+GostR3410_get_pk_digest(int nid)
{
switch (nid) {
case NID_id_GostR3411_94_CryptoProParamSet:
@@ -101,22 +103,26 @@ static const GostR3410_params GostR3410_512_params[] = {
{ NULL, NID_undef },
};
-int GostR3410_256_param_id(const char *value)
+int
+GostR3410_256_param_id(const char *value)
{
int i;
+
for (i = 0; GostR3410_256_params[i].nid != NID_undef; i++) {
- if (!strcasecmp(GostR3410_256_params[i].name, value))
+ if (strcasecmp(GostR3410_256_params[i].name, value) == 0)
return GostR3410_256_params[i].nid;
}
return NID_undef;
}
-int GostR3410_512_param_id(const char *value)
+int
+GostR3410_512_param_id(const char *value)
{
int i;
+
for (i = 0; GostR3410_512_params[i].nid != NID_undef; i++) {
- if (!strcasecmp(GostR3410_512_params[i].name, value))
+ if (strcasecmp(GostR3410_512_params[i].name, value) == 0)
return GostR3410_512_params[i].nid;
}
diff --git a/lib/libssl/src/crypto/gost/gostr341001_pmeth.c b/lib/libssl/src/crypto/gost/gostr341001_pmeth.c
index 77a84a36572..afcf8f973a5 100644
--- a/lib/libssl/src/crypto/gost/gostr341001_pmeth.c
+++ b/lib/libssl/src/crypto/gost/gostr341001_pmeth.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gostr341001_pmeth.c,v 1.4 2014/11/09 19:28:44 miod Exp $ */
+/* $OpenBSD: gostr341001_pmeth.c,v 1.5 2014/11/09 23:06:52 miod Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -65,7 +65,8 @@
#include "gost_locl.h"
#include "gost_asn1.h"
-static ECDSA_SIG *unpack_signature_cp(const unsigned char *sig, size_t siglen)
+static ECDSA_SIG *
+unpack_signature_cp(const unsigned char *sig, size_t siglen)
{
ECDSA_SIG *s;
@@ -79,12 +80,13 @@ static ECDSA_SIG *unpack_signature_cp(const unsigned char *sig, size_t siglen)
return s;
}
-static int pack_signature_cp(ECDSA_SIG * s, int order, unsigned char *sig, size_t * siglen)
+static int
+pack_signature_cp(ECDSA_SIG *s, int order, unsigned char *sig, size_t *siglen)
{
int r_len = BN_num_bytes(s->r);
int s_len = BN_num_bytes(s->s);
- if ((r_len > order) || (s_len > order))
+ if (r_len > order || s_len > order)
return 0;
*siglen = 2 * order;
@@ -96,7 +98,8 @@ static int pack_signature_cp(ECDSA_SIG * s, int order, unsigned char *sig, size_
return 1;
}
-static ECDSA_SIG *unpack_signature_le(const unsigned char *sig, size_t siglen)
+static ECDSA_SIG *
+unpack_signature_le(const unsigned char *sig, size_t siglen)
{
ECDSA_SIG *s;
@@ -110,7 +113,8 @@ static ECDSA_SIG *unpack_signature_le(const unsigned char *sig, size_t siglen)
return s;
}
-static int pack_signature_le(ECDSA_SIG * s, int order, unsigned char *sig, size_t * siglen)
+static int
+pack_signature_le(ECDSA_SIG *s, int order, unsigned char *sig, size_t *siglen)
{
*siglen = 2 * order;
memset(sig, 0, *siglen);
@@ -259,7 +263,7 @@ static int pkey_gost01_verify(EVP_PKEY_CTX * ctx, const unsigned char *sig,
ECDSA_SIG *s = NULL;
BIGNUM *md;
- if (!pub_key)
+ if (pub_key == NULL)
return 0;
switch (pctx->sig_format) {
case GOST_SIG_FORMAT_SR_BE:
@@ -269,10 +273,10 @@ static int pkey_gost01_verify(EVP_PKEY_CTX * ctx, const unsigned char *sig,
s = unpack_signature_le(sig, siglen);
break;
}
- if (!s)
+ if (s == NULL)
return 0;
md = GOST_le2bn(tbs, tbs_len, NULL);
- if (!md)
+ if (md == NULL)
goto err;
ok = gost2001_do_verify(md, s, pub_key->pkey.gost);
@@ -341,34 +345,36 @@ int pkey_gost01_decrypt(EVP_PKEY_CTX * pctx, unsigned char *key,
EVP_PKEY *eph_key = NULL, *peerkey = NULL;
int nid;
- if (!key) {
+ if (key == NULL) {
*key_len = 32;
return 1;
}
gkt = d2i_GOST_KEY_TRANSPORT(NULL, (const unsigned char **)&p, in_len);
- if (!gkt) {
+ if (gkt == NULL) {
GOSTerr(GOST_F_PKEY_GOST01_DECRYPT,
- GOST_R_ERROR_PARSING_KEY_TRANSPORT_INFO);
+ GOST_R_ERROR_PARSING_KEY_TRANSPORT_INFO);
return -1;
}
/* If key transport structure contains public key, use it */
eph_key = X509_PUBKEY_get(gkt->key_agreement_info->ephem_key);
- if (eph_key) {
+ if (eph_key != NULL) {
if (EVP_PKEY_derive_set_peer(pctx, eph_key) <= 0) {
GOSTerr(GOST_F_PKEY_GOST01_DECRYPT,
- GOST_R_INCOMPATIBLE_PEER_KEY);
+ GOST_R_INCOMPATIBLE_PEER_KEY);
goto err;
}
} else {
/* Set control "public key from client certificate used" */
- if (EVP_PKEY_CTX_ctrl(pctx, -1, -1, EVP_PKEY_CTRL_PEER_KEY, 3, NULL) <= 0) {
- GOSTerr(GOST_F_PKEY_GOST01_DECRYPT, GOST_R_CTRL_CALL_FAILED);
+ if (EVP_PKEY_CTX_ctrl(pctx, -1, -1, EVP_PKEY_CTRL_PEER_KEY, 3,
+ NULL) <= 0) {
+ GOSTerr(GOST_F_PKEY_GOST01_DECRYPT,
+ GOST_R_CTRL_CALL_FAILED);
goto err;
}
}
peerkey = EVP_PKEY_CTX_get0_peerkey(pctx);
- if (!peerkey) {
+ if (peerkey == NULL) {
GOSTerr(GOST_F_PKEY_GOST01_DECRYPT, GOST_R_NO_PEER_KEY);
goto err;
}
@@ -408,7 +414,7 @@ int pkey_gost01_derive(EVP_PKEY_CTX * ctx, unsigned char *key,
EVP_PKEY *peer_key = EVP_PKEY_CTX_get0_peerkey(ctx);
struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
- if (!data->shared_ukm) {
+ if (data->shared_ukm == NULL) {
GOSTerr(GOST_F_PKEY_GOST01_DERIVE, GOST_R_UKM_NOT_SET);
return 0;
}
@@ -573,17 +579,17 @@ static int pkey_gost01_ctrl(EVP_PKEY_CTX * ctx, int type, int p1, void *p2)
}
}
-static int pkey_gost01_ctrl_str(EVP_PKEY_CTX * ctx,
- const char *type, const char *value)
+static int
+pkey_gost01_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value)
{
int param_nid = NID_undef;
int digest_nid = NID_undef;
- if (!strcmp(type, "paramset")) {
- if (!value) {
+ if (strcmp(type, "paramset") == 0) {
+ if (value == NULL)
return 0;
- }
- if (!pkey_gost01_ctrl(ctx, EVP_PKEY_CTRL_GOST_GET_DIGEST, 0, &digest_nid))
+ if (pkey_gost01_ctrl(ctx, EVP_PKEY_CTRL_GOST_GET_DIGEST, 0,
+ &digest_nid) == 0)
return 0;
if (digest_nid == NID_id_tc26_gost3411_2012_512)
param_nid = GostR3410_512_param_id(value);
@@ -595,23 +601,24 @@ static int pkey_gost01_ctrl_str(EVP_PKEY_CTX * ctx,
return 0;
return pkey_gost01_ctrl(ctx, EVP_PKEY_CTRL_GOST_PARAMSET,
- param_nid, NULL);
+ param_nid, NULL);
}
- if (!strcmp(type, "dgst")) {
- if (!value)
+ if (strcmp(type, "dgst") == 0) {
+ if (value == NULL)
return 0;
- else if (!strcmp(value, "gost94") || !strcmp(value, "md_gost94"))
+ else if (strcmp(value, "gost94") == 0 ||
+ strcmp(value, "md_gost94") == 0)
digest_nid = NID_id_GostR3411_94_CryptoProParamSet;
- else if (!strcmp(value, "streebog256"))
+ else if (strcmp(value, "streebog256") == 0)
digest_nid = NID_id_tc26_gost3411_2012_256;
- else if (!strcmp(value, "streebog512"))
+ else if (strcmp(value, "streebog512") == 0)
digest_nid = NID_id_tc26_gost3411_2012_512;
if (digest_nid == NID_undef)
return 0;
return pkey_gost01_ctrl(ctx, EVP_PKEY_CTRL_GOST_SET_DIGEST,
- digest_nid, NULL);
+ digest_nid, NULL);
}
return -2;
}
diff --git a/lib/libssl/src/crypto/gost/gostr341194.c b/lib/libssl/src/crypto/gost/gostr341194.c
index 706bf3d4316..3151d9fe127 100644
--- a/lib/libssl/src/crypto/gost/gostr341194.c
+++ b/lib/libssl/src/crypto/gost/gostr341194.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gostr341194.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */
+/* $OpenBSD: gostr341194.c,v 1.2 2014/11/09 23:06:52 miod Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -62,17 +62,19 @@
/* Following functions are various bit meshing routines used in
* GOST R 34.11-94 algorithms */
-static void swap_bytes(unsigned char *w, unsigned char *k)
+static void
+swap_bytes(unsigned char *w, unsigned char *k)
{
int i, j;
+
for (i = 0; i < 4; i++)
for (j = 0; j < 8; j++)
k[i + 4 * j] = w[8 * i + j];
-
}
/* was A_A */
-static void circle_xor8(const unsigned char *w, unsigned char *k)
+static void
+circle_xor8(const unsigned char *w, unsigned char *k)
{
unsigned char buf[8];
int i;
@@ -84,9 +86,11 @@ static void circle_xor8(const unsigned char *w, unsigned char *k)
}
/* was R_R */
-static void transform_3(unsigned char *data)
+static void
+transform_3(unsigned char *data)
{
unsigned short int acc;
+
acc = (data[0] ^ data[2] ^ data[4] ^ data[6] ^ data[24] ^ data[30]) |
((data[1] ^ data[3] ^ data[5] ^ data[7] ^ data[25] ^ data[31]) << 8);
memmove(data, data + 2, 30);
@@ -95,7 +99,8 @@ static void transform_3(unsigned char *data)
}
/* Adds blocks of N bytes modulo 2**(8*n). Returns carry*/
-static int add_blocks(int n, unsigned char *left, const unsigned char *right)
+static int
+add_blocks(int n, unsigned char *left, const unsigned char *right)
{
int i;
int carry = 0;
@@ -110,10 +115,12 @@ static int add_blocks(int n, unsigned char *left, const unsigned char *right)
}
/* Xor two sequences of bytes */
-static void xor_blocks(unsigned char *result, const unsigned char *a,
- const unsigned char *b, size_t len)
+static void
+xor_blocks(unsigned char *result, const unsigned char *a,
+ const unsigned char *b, size_t len)
{
size_t i;
+
for (i = 0; i < len; i++)
result[i] = a[i] ^ b[i];
}
@@ -122,7 +129,8 @@ static void xor_blocks(unsigned char *result, const unsigned char *a,
* Calculate H(i+1) = Hash(Hi,Mi)
* Where H and M are 32 bytes long
*/
-static int hash_step(GOSTR341194_CTX *c, unsigned char *H, const unsigned char *M)
+static int
+hash_step(GOSTR341194_CTX *c, unsigned char *H, const unsigned char *M)
{
unsigned char U[32], W[32], V[32], S[32], Key[32];
int i;
@@ -191,15 +199,18 @@ static int hash_step(GOSTR341194_CTX *c, unsigned char *H, const unsigned char *
return 1;
}
-int GOSTR341194_Init(GOSTR341194_CTX *c, int nid)
+int
+GOSTR341194_Init(GOSTR341194_CTX *c, int nid)
{
- memset (c,0,sizeof(*c));
+ memset(c, 0, sizeof(*c));
return Gost2814789_set_sbox(&c->cipher, nid);
}
-static void GOSTR341194_block_data_order(GOSTR341194_CTX *ctx, const void *p, size_t num)
+static void
+GOSTR341194_block_data_order(GOSTR341194_CTX *ctx, const void *p, size_t num)
{
int i;
+
for (i = 0; i < num; i++) {
hash_step(ctx, ctx->H, p);
add_blocks(32, ctx->S, p);
@@ -219,7 +230,8 @@ static void GOSTR341194_block_data_order(GOSTR341194_CTX *ctx, const void *p, si
#include "md32_common.h"
-int GOSTR341194_Final(unsigned char *md, GOSTR341194_CTX * c)
+int
+GOSTR341194_Final(unsigned char *md, GOSTR341194_CTX * c)
{
unsigned char *p = (unsigned char *)c->data;
unsigned char T[32];
@@ -233,7 +245,7 @@ int GOSTR341194_Final(unsigned char *md, GOSTR341194_CTX * c)
p = T;
HOST_l2c(c->Nl, p);
HOST_l2c(c->Nh, p);
- memset(p, 0, 32-8);
+ memset(p, 0, 32 - 8);
hash_step(c, c->H, T);
hash_step(c, c->H, c->S);
@@ -242,7 +254,8 @@ int GOSTR341194_Final(unsigned char *md, GOSTR341194_CTX * c)
return 1;
}
-unsigned char *GOSTR341194(const unsigned char *d, size_t n, unsigned char *md, int nid)
+unsigned char *
+GOSTR341194(const unsigned char *d, size_t n, unsigned char *md, int nid)
{
GOSTR341194_CTX c;
static unsigned char m[GOSTR341194_LENGTH];
diff --git a/lib/libssl/src/crypto/gost/streebog.c b/lib/libssl/src/crypto/gost/streebog.c
index c621c41daac..0a49fca5d9d 100644
--- a/lib/libssl/src/crypto/gost/streebog.c
+++ b/lib/libssl/src/crypto/gost/streebog.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: streebog.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */
+/* $OpenBSD: streebog.c,v 1.2 2014/11/09 23:06:52 miod Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -1166,7 +1166,9 @@ static const STREEBOG_LONG64 C16[12][8] =
#define PULL64(x) (B(x,0,0)|B(x,1,1)|B(x,2,2)|B(x,3,3)|B(x,4,4)|B(x,5,5)|B(x,6,6)|B(x,7,7))
#define SWAB64(x) (B(x,0,7)|B(x,1,6)|B(x,2,5)|B(x,3,4)|B(x,4,3)|B(x,5,2)|B(x,6,1)|B(x,7,0))
-static inline STREEBOG_LONG64 multipermute(const STREEBOG_LONG64 *in, int i) {
+static inline STREEBOG_LONG64
+multipermute(const STREEBOG_LONG64 *in, int i)
+{
STREEBOG_LONG64 t = 0;
t ^= A_PI_table[0][(in[0] >> (i * 8)) & 0xff];
@@ -1181,30 +1183,33 @@ static inline STREEBOG_LONG64 multipermute(const STREEBOG_LONG64 *in, int i) {
return t;
}
-static void transform(STREEBOG_LONG64 *out, const STREEBOG_LONG64 *a, const STREEBOG_LONG64 *b)
+static void
+transform(STREEBOG_LONG64 *out, const STREEBOG_LONG64 *a,
+ const STREEBOG_LONG64 *b)
{
- STREEBOG_LONG64 tmp[8];
+ STREEBOG_LONG64 tmp[8];
- tmp[0] = a[0] ^ b[0];
- tmp[1] = a[1] ^ b[1];
- tmp[2] = a[2] ^ b[2];
- tmp[3] = a[3] ^ b[3];
- tmp[4] = a[4] ^ b[4];
- tmp[5] = a[5] ^ b[5];
- tmp[6] = a[6] ^ b[6];
- tmp[7] = a[7] ^ b[7];
+ tmp[0] = a[0] ^ b[0];
+ tmp[1] = a[1] ^ b[1];
+ tmp[2] = a[2] ^ b[2];
+ tmp[3] = a[3] ^ b[3];
+ tmp[4] = a[4] ^ b[4];
+ tmp[5] = a[5] ^ b[5];
+ tmp[6] = a[6] ^ b[6];
+ tmp[7] = a[7] ^ b[7];
- out[0] = multipermute(tmp, 0);
- out[1] = multipermute(tmp, 1);
- out[2] = multipermute(tmp, 2);
- out[3] = multipermute(tmp, 3);
- out[4] = multipermute(tmp, 4);
- out[5] = multipermute(tmp, 5);
- out[6] = multipermute(tmp, 6);
- out[7] = multipermute(tmp, 7);
+ out[0] = multipermute(tmp, 0);
+ out[1] = multipermute(tmp, 1);
+ out[2] = multipermute(tmp, 2);
+ out[3] = multipermute(tmp, 3);
+ out[4] = multipermute(tmp, 4);
+ out[5] = multipermute(tmp, 5);
+ out[6] = multipermute(tmp, 6);
+ out[7] = multipermute(tmp, 7);
}
-static inline void gN(STREEBOG_LONG64 *h, STREEBOG_LONG64 *m, STREEBOG_LONG64 *N)
+static inline void
+gN(STREEBOG_LONG64 *h, STREEBOG_LONG64 *m, STREEBOG_LONG64 *N)
{
STREEBOG_LONG64 K[8];
STREEBOG_LONG64 T[8];
@@ -1230,7 +1235,8 @@ static inline void gN(STREEBOG_LONG64 *h, STREEBOG_LONG64 *m, STREEBOG_LONG64 *N
}
-static void streebog_single_block(STREEBOG_CTX * ctx, const unsigned char *in, size_t num)
+static void
+streebog_single_block(STREEBOG_CTX *ctx, const unsigned char *in, size_t num)
{
STREEBOG_LONG64 M[8], l;
int i;
@@ -1261,14 +1267,17 @@ static void streebog_single_block(STREEBOG_CTX * ctx, const unsigned char *in, s
-static void streebog_block_data_order(STREEBOG_CTX * ctx, const void *in, size_t num)
+static void
+streebog_block_data_order(STREEBOG_CTX *ctx, const void *in, size_t num)
{
int i;
+
for (i = 0; i < num; i++)
streebog_single_block(ctx, in + i * STREEBOG_CBLOCK, 64 * 8);
}
-int STREEBOG512_Final(unsigned char *md, STREEBOG_CTX * c)
+int
+STREEBOG512_Final(unsigned char *md, STREEBOG_CTX *c)
{
int n;
unsigned char *p = (unsigned char *)c->data;
@@ -1281,7 +1290,7 @@ int STREEBOG512_Final(unsigned char *md, STREEBOG_CTX * c)
n = c->num;
p[n++] = 1;
- memset(p+n, 0, STREEBOG_CBLOCK - n);
+ memset(p + n, 0, STREEBOG_CBLOCK - n);
streebog_single_block(c, p, c->num * 8);
@@ -1291,7 +1300,7 @@ int STREEBOG512_Final(unsigned char *md, STREEBOG_CTX * c)
for (n = 0; n < STREEBOG_LBLOCK; n++)
c->h[n] = SWAB64(c->h[n]);
- if (md == 0)
+ if (md == NULL)
return 0;
switch (c->md_len) {
@@ -1332,12 +1341,14 @@ int STREEBOG512_Final(unsigned char *md, STREEBOG_CTX * c)
return 1;
}
-int STREEBOG256_Final(unsigned char *md, STREEBOG_CTX * c)
+int
+STREEBOG256_Final(unsigned char *md, STREEBOG_CTX * c)
{
return STREEBOG512_Final(md, c);
}
-int STREEBOG512_Update(STREEBOG_CTX * c, const void *_data, size_t len)
+int
+STREEBOG512_Update(STREEBOG_CTX *c, const void *_data, size_t len)
{
unsigned char *p = (unsigned char *)c->data;
const unsigned char *data = (const unsigned char *)_data;
@@ -1376,17 +1387,20 @@ int STREEBOG512_Update(STREEBOG_CTX * c, const void *_data, size_t len)
return 1;
}
-int STREEBOG256_Update(STREEBOG_CTX * c, const void *data, size_t len)
+int
+STREEBOG256_Update(STREEBOG_CTX *c, const void *data, size_t len)
{
return STREEBOG512_Update(c, data, len);
}
-void STREEBOG512_Transform(STREEBOG_CTX * c, const unsigned char *data)
+void
+STREEBOG512_Transform(STREEBOG_CTX *c, const unsigned char *data)
{
streebog_block_data_order(c, data, 1);
}
-int STREEBOG256_Init(STREEBOG_CTX * c)
+int
+STREEBOG256_Init(STREEBOG_CTX *c)
{
memset(c, 0, sizeof(*c));
memset(c->h, 1, sizeof(c->h));
@@ -1395,7 +1409,8 @@ int STREEBOG256_Init(STREEBOG_CTX * c)
return 1;
}
-int STREEBOG512_Init(STREEBOG_CTX * c)
+int
+STREEBOG512_Init(STREEBOG_CTX *c)
{
memset(c, 0, sizeof(*c));
memset(c->h, 0, sizeof(c->h));
@@ -1405,7 +1420,8 @@ int STREEBOG512_Init(STREEBOG_CTX * c)
return 1;
}
-unsigned char *STREEBOG256(const unsigned char *d, size_t n, unsigned char *md)
+unsigned char *
+STREEBOG256(const unsigned char *d, size_t n, unsigned char *md)
{
STREEBOG_CTX c;
static unsigned char m[STREEBOG256_LENGTH];
@@ -1419,7 +1435,8 @@ unsigned char *STREEBOG256(const unsigned char *d, size_t n, unsigned char *md)
return (md);
}
-unsigned char *STREEBOG512(const unsigned char *d, size_t n, unsigned char *md)
+unsigned char *
+STREEBOG512(const unsigned char *d, size_t n, unsigned char *md)
{
STREEBOG_CTX c;
static unsigned char m[STREEBOG512_LENGTH];