*/
#ifndef HEADER_GOST_ERR_H
-#define HEADER_GOST_ERR_H
+# define HEADER_GOST_ERR_H
-#ifdef __cplusplus
+# ifdef __cplusplus
extern "C" {
-#endif
+# endif
/* BEGIN ERROR CODES */
/*
* The following lines are auto generated by the script mkerr.pl. Any changes
* made after this point may be overwritten when the script is next run.
*/
-void ERR_load_GOST_strings(void);
-void ERR_unload_GOST_strings(void);
-void ERR_GOST_error(int function, int reason, char *file, int line);
+ void ERR_load_GOST_strings(void);
+ void ERR_unload_GOST_strings(void);
+ void ERR_GOST_error(int function, int reason, char *file, int line);
# define GOSTerr(f,r) ERR_GOST_error((f),(r),__FILE__,__LINE__)
/* Error codes for the GOST functions. */
# define GOST_R_UNSUPPORTED_CIPHER_CTL_COMMAND 126
# define GOST_R_UNSUPPORTED_PARAMETER_SET 127
-#ifdef __cplusplus
+# ifdef __cplusplus
}
-#endif
+# endif
#endif
#include <limits.h>
#include <fcntl.h>
#ifdef _WIN32
-#include <io.h>
+# include <io.h>
#endif
#include <string.h>
#include "gosthash2012.h"
while ((c = getopt(argc, argv, "bxlvc::")) != -1) {
switch (c) {
- case 'b':
- open_mode = open_mode | O_BINARY;
- break;
+ case 'b':
+ open_mode = open_mode | O_BINARY;
+ break;
case 'v':
verbose = 1;
break;
}
}
if (check_file) {
- char inhash[MAX_HASH_SIZE+1], calcsum[MAX_HASH_SIZE+1], filename[PATH_MAX];
+ char inhash[MAX_HASH_SIZE + 1], calcsum[MAX_HASH_SIZE + 1],
+ filename[PATH_MAX];
int failcount = 0, count = 0;;
if (check_file == stdin && optind < argc) {
check_file = fopen(argv[optind], "r");
count++;
if (!hash_file(&ctx, filename, calcsum, open_mode)) {
errors++;
- continue;
+ continue;
}
- if (!strncmp(calcsum, inhash, hashsize/4+1)) {
+ if (!strncmp(calcsum, inhash, hashsize / 4 + 1)) {
if (verbose) {
fprintf(stderr, "%s\tOK\n", filename);
}
} else if (optind == argc) {
char sum[65];
#ifdef _WIN32
- if (open_mode & O_BINARY) {
- _setmode(fileno(stdin), O_BINARY);
- }
+ if (open_mode & O_BINARY) {
+ _setmode(fileno(stdin), O_BINARY);
+ }
#endif
if (!hash_stream(&ctx, fileno(stdin), sum)) {
perror("stdin");
int hash_stream(gost_hash_ctx * ctx, int fd, char *sum)
{
unsigned char buffer[BUF_SIZE];
- unsigned char reverted_buffer[BUF_SIZE];
+ unsigned char reverted_buffer[BUF_SIZE];
ssize_t bytes;
- int i,j,k;
+ int i, j, k;
start_hash12(ctx);
while ((bytes = read(fd, buffer, BUF_SIZE)) > 0) {
hash12_block(ctx, reverted_buffer, bytes);
int get_line(FILE *f, char *hash, char *filename, int verbose)
{
int i, len;
- int hashstrlen = hashsize/4;
+ int hashstrlen = hashsize / 4;
while (!feof(f)) {
if (!fgets(filename, PATH_MAX, f))
return 0;
len = strlen(filename);
- if (len < hashstrlen+2) {
+ if (len < hashstrlen + 2) {
goto nextline;
}
if (filename[hashstrlen] != ' ') {
hash[hashstrlen] = 0;
while (filename[--len] == '\n' || filename[len] == '\r')
filename[len] = 0;
- memmove(filename, filename + hashstrlen+1, len - hashstrlen +1);
+ memmove(filename, filename + hashstrlen + 1, len - hashstrlen + 1);
return 1;
- nextline:
+ nextline:
if (verbose)
printf(filename);
}
return 0;
}
-
static int param_copy_gost_ec(EVP_PKEY *to, const EVP_PKEY *from)
{
EC_KEY *eto = EVP_PKEY_get0(to);
ret = i2d_ASN1_OCTET_STRING(octet, &buf);
ASN1_BIT_STRING_free(octet);
-err:
+ err:
if (X)
BN_free(X);
if (Y)
#include "gost_lcl.h"
ASN1_NDEF_SEQUENCE(GOST_KEY_TRANSPORT) = {
- ASN1_SIMPLE(GOST_KEY_TRANSPORT, key_info, GOST_KEY_INFO),
- ASN1_IMP(GOST_KEY_TRANSPORT, key_agreement_info, GOST_KEY_AGREEMENT_INFO, 0)
-} ASN1_NDEF_SEQUENCE_END(GOST_KEY_TRANSPORT)
+ ASN1_SIMPLE(GOST_KEY_TRANSPORT, key_info, GOST_KEY_INFO),
+ ASN1_IMP(GOST_KEY_TRANSPORT, key_agreement_info,
+ GOST_KEY_AGREEMENT_INFO, 0)
+}
-IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_TRANSPORT)
+ASN1_NDEF_SEQUENCE_END(GOST_KEY_TRANSPORT)
-ASN1_NDEF_SEQUENCE(GOST_KEY_INFO) = {
- ASN1_SIMPLE(GOST_KEY_INFO, encrypted_key, ASN1_OCTET_STRING),
- ASN1_SIMPLE(GOST_KEY_INFO, imit, ASN1_OCTET_STRING)
-} ASN1_NDEF_SEQUENCE_END(GOST_KEY_INFO)
-
-IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_INFO)
+ IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_TRANSPORT)
-ASN1_NDEF_SEQUENCE(GOST_KEY_AGREEMENT_INFO) = {
- ASN1_SIMPLE(GOST_KEY_AGREEMENT_INFO, cipher, ASN1_OBJECT),
+ ASN1_NDEF_SEQUENCE(GOST_KEY_INFO) =
+{
+ ASN1_SIMPLE(GOST_KEY_INFO, encrypted_key, ASN1_OCTET_STRING),
+ ASN1_SIMPLE(GOST_KEY_INFO, imit, ASN1_OCTET_STRING)
+} ASN1_NDEF_SEQUENCE_END(GOST_KEY_INFO)
+ IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_INFO)
+ ASN1_NDEF_SEQUENCE(GOST_KEY_AGREEMENT_INFO) =
+{
+ ASN1_SIMPLE(GOST_KEY_AGREEMENT_INFO, cipher, ASN1_OBJECT),
ASN1_IMP_OPT(GOST_KEY_AGREEMENT_INFO, ephem_key, X509_PUBKEY, 0),
ASN1_SIMPLE(GOST_KEY_AGREEMENT_INFO, eph_iv, ASN1_OCTET_STRING)
} ASN1_NDEF_SEQUENCE_END(GOST_KEY_AGREEMENT_INFO)
-
-IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_AGREEMENT_INFO)
-
-ASN1_NDEF_SEQUENCE(GOST_KEY_PARAMS) = {
- ASN1_SIMPLE(GOST_KEY_PARAMS, key_params, ASN1_OBJECT),
+ IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_AGREEMENT_INFO)
+ ASN1_NDEF_SEQUENCE(GOST_KEY_PARAMS) =
+{
+ASN1_SIMPLE(GOST_KEY_PARAMS, key_params, ASN1_OBJECT),
ASN1_SIMPLE(GOST_KEY_PARAMS, hash_params, ASN1_OBJECT),
- ASN1_OPT(GOST_KEY_PARAMS, cipher_params, ASN1_OBJECT),
-} ASN1_NDEF_SEQUENCE_END(GOST_KEY_PARAMS)
-
-IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_PARAMS)
-
-ASN1_NDEF_SEQUENCE(GOST_CIPHER_PARAMS) = {
- ASN1_SIMPLE(GOST_CIPHER_PARAMS, iv, ASN1_OCTET_STRING),
- ASN1_SIMPLE(GOST_CIPHER_PARAMS, enc_param_set, ASN1_OBJECT),
-} ASN1_NDEF_SEQUENCE_END(GOST_CIPHER_PARAMS)
-
-IMPLEMENT_ASN1_FUNCTIONS(GOST_CIPHER_PARAMS)
-
-ASN1_NDEF_SEQUENCE(GOST_CLIENT_KEY_EXCHANGE_PARAMS) = { /* FIXME incomplete */
+ ASN1_OPT(GOST_KEY_PARAMS, cipher_params,
+ ASN1_OBJECT),} ASN1_NDEF_SEQUENCE_END(GOST_KEY_PARAMS)
+ IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_PARAMS)
+ ASN1_NDEF_SEQUENCE(GOST_CIPHER_PARAMS) =
+{
+ASN1_SIMPLE(GOST_CIPHER_PARAMS, iv, ASN1_OCTET_STRING),
+ ASN1_SIMPLE(GOST_CIPHER_PARAMS, enc_param_set,
+ ASN1_OBJECT),}
+ASN1_NDEF_SEQUENCE_END(GOST_CIPHER_PARAMS)
+ IMPLEMENT_ASN1_FUNCTIONS(GOST_CIPHER_PARAMS)
+ ASN1_NDEF_SEQUENCE(GOST_CLIENT_KEY_EXCHANGE_PARAMS) =
+{ /* FIXME incomplete */
ASN1_SIMPLE(GOST_CLIENT_KEY_EXCHANGE_PARAMS, gkt, GOST_KEY_TRANSPORT)
} ASN1_NDEF_SEQUENCE_END(GOST_CLIENT_KEY_EXCHANGE_PARAMS)
-IMPLEMENT_ASN1_FUNCTIONS(GOST_CLIENT_KEY_EXCHANGE_PARAMS)
+ IMPLEMENT_ASN1_FUNCTIONS(GOST_CLIENT_KEY_EXCHANGE_PARAMS)
-ASN1_NDEF_SEQUENCE(MASKED_GOST_KEY) = {
+ ASN1_NDEF_SEQUENCE(MASKED_GOST_KEY) =
+{
ASN1_SIMPLE(MASKED_GOST_KEY, masked_priv_key, ASN1_OCTET_STRING),
- ASN1_SIMPLE(MASKED_GOST_KEY, public_key, ASN1_OCTET_STRING)
+ ASN1_SIMPLE(MASKED_GOST_KEY, public_key, ASN1_OCTET_STRING)
} ASN1_NDEF_SEQUENCE_END(MASKED_GOST_KEY)
-
-IMPLEMENT_ASN1_FUNCTIONS(MASKED_GOST_KEY)
+ IMPLEMENT_ASN1_FUNCTIONS(MASKED_GOST_KEY)
static int gost_cipher_do_cfb(EVP_CIPHER_CTX *ctx, unsigned char *out,
const unsigned char *in, size_t inl);
/* Handles block of data in CBC mode */
-static int gost_cipher_do_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out,
- const unsigned char *in, size_t inl);
+static int gost_cipher_do_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out,
+ const unsigned char *in, size_t inl);
/* Handles block of data in CNT mode */
static int gost_cipher_do_cnt(EVP_CIPHER_CTX *ctx, unsigned char *out,
const unsigned char *in, size_t inl);
NULL,
};
-EVP_CIPHER cipher_gost_cbc =
- {
+EVP_CIPHER cipher_gost_cbc = {
NID_gost89_cbc,
- 8,/*block_size*/
- 32,/*key_size*/
- 8,/*iv_len */
- EVP_CIPH_CBC_MODE|
- EVP_CIPH_CUSTOM_IV| EVP_CIPH_RAND_KEY | EVP_CIPH_ALWAYS_CALL_INIT,
+ 8, /*block_size */
+ 32, /*key_size */
+ 8, /*iv_len */
+ EVP_CIPH_CBC_MODE |
+ EVP_CIPH_CUSTOM_IV | EVP_CIPH_RAND_KEY | EVP_CIPH_ALWAYS_CALL_INIT,
gost_cipher_init_cbc,
gost_cipher_do_cbc,
gost_cipher_cleanup,
- sizeof(struct ossl_gost_cipher_ctx),/* ctx_size */
+ sizeof(struct ossl_gost_cipher_ctx), /* ctx_size */
gost89_set_asn1_parameters,
gost89_get_asn1_parameters,
gost_cipher_ctl,
NULL,
- };
+};
EVP_CIPHER cipher_gost_cpacnt = {
NID_gost89_cnt,
EVP_CIPH_CBC_MODE);
}
-
/*
* Wrapper around gostcrypt function from gost89.c which perform key meshing
* when nesseccary
/* GOST encryptoon in CBC mode */
int gost_cipher_do_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out,
- const unsigned char *in, size_t inl)
- {
- OPENSSL_assert(inl % 8 ==0);
+ const unsigned char *in, size_t inl)
+{
+ OPENSSL_assert(inl % 8 == 0);
unsigned char b[8];
- const unsigned char *in_ptr=in;
- unsigned char *out_ptr=out;
+ const unsigned char *in_ptr = in;
+ unsigned char *out_ptr = out;
int i;
struct ossl_gost_cipher_ctx *c = ctx->cipher_data;
- if (ctx->encrypt)
- {
- while(inl>0)
- {
- for (i=0;i<8;i++)
- {
- b[i]=ctx->iv[i]^in_ptr[i];
- }
- gostcrypt(&(c->cctx),b,out_ptr);
- memcpy(ctx->iv,out_ptr,8);
- out_ptr+=8;
- in_ptr+=8;
- inl-=8;
+ if (ctx->encrypt) {
+ while (inl > 0) {
+ for (i = 0; i < 8; i++) {
+ b[i] = ctx->iv[i] ^ in_ptr[i];
}
+ gostcrypt(&(c->cctx), b, out_ptr);
+ memcpy(ctx->iv, out_ptr, 8);
+ out_ptr += 8;
+ in_ptr += 8;
+ inl -= 8;
}
- else
- {
- while (inl>0) {
- gostdecrypt(&(c->cctx),in_ptr,b);
- for (i=0;i<8;i++)
- {
- out_ptr[i]=ctx->iv[i]^b[i];
- }
- memcpy(ctx->iv,in_ptr,8);
- out_ptr+=8;
- in_ptr+=8;
- inl-=8;
+ } else {
+ while (inl > 0) {
+ gostdecrypt(&(c->cctx), in_ptr, b);
+ for (i = 0; i < 8; i++) {
+ out_ptr[i] = ctx->iv[i] ^ b[i];
}
+ memcpy(ctx->iv, in_ptr, 8);
+ out_ptr += 8;
+ in_ptr += 8;
+ inl -= 8;
}
- return 1;
}
+ return 1;
+}
+
/* GOST encryption in CFB mode */
int gost_cipher_do_cfb(EVP_CIPHER_CTX *ctx, unsigned char *out,
const unsigned char *in, size_t inl)
return 1;
case EVP_MD_CTRL_SET_KEY:
{
- struct ossl_gost_imit_ctx *gost_imit_ctx = ctx->md_data;
+ struct ossl_gost_imit_ctx *gost_imit_ctx = ctx->md_data;
- if (ctx->digest->init(ctx) <= 0) {
- GOSTerr(GOST_F_GOST_IMIT_CTRL, GOST_R_MAC_KEY_NOT_SET);
- return 0;
- }
- ctx->flags |= EVP_MD_CTX_FLAG_NO_INIT;
+ if (ctx->digest->init(ctx) <= 0) {
+ GOSTerr(GOST_F_GOST_IMIT_CTRL, GOST_R_MAC_KEY_NOT_SET);
+ return 0;
+ }
+ ctx->flags |= EVP_MD_CTX_FLAG_NO_INIT;
if (arg == 0) {
- struct gost_mac_key *key = (struct gost_mac_key*) ptr;
- if (key->mac_param_nid != NID_undef) {
- const struct gost_cipher_info *param = get_encryption_params(OBJ_nid2obj(key->mac_param_nid));
- if (param == NULL)
- {
- GOSTerr(GOST_F_GOST_IMIT_CTRL, GOST_R_INVALID_MAC_PARAMS);
- return 0;
- }
- gost_init(&(gost_imit_ctx->cctx), param->sblock);
- }
- gost_key(&(gost_imit_ctx->cctx), key->key);
+ struct gost_mac_key *key = (struct gost_mac_key *)ptr;
+ if (key->mac_param_nid != NID_undef) {
+ const struct gost_cipher_info *param =
+ get_encryption_params(OBJ_nid2obj
+ (key->mac_param_nid));
+ if (param == NULL) {
+ GOSTerr(GOST_F_GOST_IMIT_CTRL,
+ GOST_R_INVALID_MAC_PARAMS);
+ return 0;
+ }
+ gost_init(&(gost_imit_ctx->cctx), param->sblock);
+ }
+ gost_key(&(gost_imit_ctx->cctx), key->key);
gost_imit_ctx->key_set = 1;
- return 1;
+ return 1;
+ } else if (arg == 32) {
+ gost_key(&(gost_imit_ctx->cctx), ptr);
+ gost_imit_ctx->key_set = 1;
+ return 1;
}
- else if (arg == 32)
- {
- gost_key(&(gost_imit_ctx->cctx), ptr);
- gost_imit_ctx->key_set = 1;
- return 1;
- }
GOSTerr(GOST_F_GOST_IMIT_CTRL, GOST_R_INVALID_MAC_KEY_SIZE);
return 0;
}
GOSTerr(GOST_F_GOST_IMIT_CTRL, GOST_R_INVALID_MAC_SIZE);
return 0;
}
- c->dgst_size=arg;
+ c->dgst_size = arg;
return 1;
}
Y = BN_CTX_get(ctx);
EC_GROUP_get_order(EC_KEY_get0_group(priv_key), order, ctx);
BN_mod_mul(p, key, UKM, order, ctx);
- if(!EC_POINT_mul(EC_KEY_get0_group(priv_key), pnt, NULL, pub_key, p, ctx)) {
+ if (!EC_POINT_mul
+ (EC_KEY_get0_group(priv_key), pnt, NULL, pub_key, p, ctx)) {
GOSTerr(GOST_F_VKO_COMPUTE_KEY, GOST_R_ERROR_POINT_MUL);
goto err;
- }
+ }
EC_POINT_get_affine_coordinates_GFp(EC_KEY_get0_group(priv_key),
pnt, X, Y, ctx);
/*
goto end;
}
ok = 1;
-end:
+ end:
if (P)
EC_POINT_free(P);
if (grp)
goto err;
}
v = BN_mod_inverse(v, e, order, ctx);
- if (!v
- || !BN_mod_mul(z1, sig->s, v, order, ctx)
+ if (!v || !BN_mod_mul(z1, sig->s, v, order, ctx)
|| !BN_sub(tmp, order, sig->r)
|| !BN_mod_mul(z2, tmp, v, order, ctx)) {
GOSTerr(GOST_F_GOST_EC_VERIFY, ERR_R_INTERNAL_ERROR);
}
ok = 1;
-end:
+ end:
if (d)
BN_free(d);
if (order)
BN_free(order);
-
+
return (ok) ? gost_ec_compute_public(ec) : 0;
}
static EVP_PKEY_METHOD *pmeth_GostR3410_2001 = NULL,
*pmeth_GostR3410_2012_256 = NULL,
*pmeth_GostR3410_2012_512 = NULL,
- *pmeth_Gost28147_MAC = NULL,
- *pmeth_Gost28147_MAC_12 = NULL;
+ *pmeth_Gost28147_MAC = NULL, *pmeth_Gost28147_MAC_12 = NULL;
static EVP_PKEY_ASN1_METHOD *ameth_GostR3410_2001 = NULL,
*ameth_GostR3410_2012_256 = NULL,
*ameth_GostR3410_2012_512 = NULL,
- *ameth_Gost28147_MAC = NULL,
- *ameth_Gost28147_MAC_12 = NULL;
+ *ameth_Gost28147_MAC = NULL, *ameth_Gost28147_MAC_12 = NULL;
static int gost_engine_init(ENGINE *e)
{
int ok = 1;
if (!digest) {
*nids = gost_digest_nids;
- return sizeof(gost_digest_nids)/sizeof(gost_digest_nids[0]) - 1;
+ return sizeof(gost_digest_nids) / sizeof(gost_digest_nids[0]) - 1;
}
if (nid == NID_id_GostR3411_94) {
*digest = &digest_gost;
int ok = 1;
if (!cipher) {
*nids = gost_cipher_nids;
- return sizeof(gost_cipher_nids)/sizeof(gost_cipher_nids[0]) - 1;
+ return sizeof(gost_cipher_nids) / sizeof(gost_cipher_nids[0]) - 1;
}
if (nid == NID_id_Gost28147_89) {
{
if (!pmeth) {
*nids = gost_pkey_meth_nids;
- return sizeof(gost_pkey_meth_nids)/sizeof(gost_pkey_meth_nids[0]) - 1;
+ return sizeof(gost_pkey_meth_nids) / sizeof(gost_pkey_meth_nids[0]) -
+ 1;
}
switch (nid) {
{
if (!ameth) {
*nids = gost_pkey_meth_nids;
- return sizeof(gost_pkey_meth_nids)/sizeof(gost_pkey_meth_nids[0]) - 1;
+ return sizeof(gost_pkey_meth_nids) / sizeof(gost_pkey_meth_nids[0]) -
+ 1;
}
switch (nid) {
case NID_id_GostR3410_2001:
} R3410_ec_params;
extern R3410_ec_params R3410_2001_paramset[],
- *R3410_2012_256_paramset,
- R3410_2012_512_paramset[];
+ *R3410_2012_256_paramset, R3410_2012_512_paramset[];
extern const ENGINE_CMD_DEFN gost_cmds[];
int gost_control_func(ENGINE *e, int cmd, long i, void *p, void (*f) (void));
struct gost_mac_pmeth_data {
short int key_set;
- short int mac_size;
- int mac_param_nid;
+ short int mac_size;
+ int mac_param_nid;
EVP_MD *md;
unsigned char key[32];
};
DECLARE_ASN1_FUNCTIONS(MASKED_GOST_KEY)
/*============== Message digest and cipher related structures ==========*/
- /*
- * Structure used as EVP_MD_CTX-md_data. It allows to avoid storing
- * in the md-data pointers to dynamically allocated memory. I
- * cannot invent better way to avoid memory leaks, because openssl
- * insist on invoking Init on Final-ed digests, and there is no
- * reliable way to find out whether pointer in the passed md_data is
- * valid or not.
- */
+ /*
+ * Structure used as EVP_MD_CTX-md_data. It allows to avoid storing
+ * in the md-data pointers to dynamically allocated memory. I
+ * cannot invent better way to avoid memory leaks, because openssl
+ * insist on invoking Init on Final-ed digests, and there is no
+ * reliable way to find out whether pointer in the passed md_data is
+ * valid or not.
+ */
struct ossl_gost_digest_ctx {
gost_hash_ctx dctx;
gost_ctx cctx;
int key_meshing;
int bytes_left;
int key_set;
- int dgst_size;
+ int dgst_size;
};
/* Table which maps parameter NID to S-blocks */
extern struct gost_cipher_info gost_cipher_list[];
static int gost_digest_final(EVP_MD_CTX *ctx, unsigned char *md);
static int gost_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from);
static int gost_digest_cleanup(EVP_MD_CTX *ctx);
-static int gost_digest_ctrl_256(EVP_MD_CTX *ctx, int type, int arg, void *ptr);
-static int gost_digest_ctrl_512(EVP_MD_CTX *ctx, int type, int arg, void *ptr);
+static int gost_digest_ctrl_256(EVP_MD_CTX *ctx, int type, int arg,
+ void *ptr);
+static int gost_digest_ctrl_512(EVP_MD_CTX *ctx, int type, int arg,
+ void *ptr);
const char micalg_256[] = "gostr3411-2012-256";
const char micalg_512[] = "gostr3411-2012-512";
}
static int gost_digest_ctrl_256(EVP_MD_CTX *ctx, int type, int arg, void *ptr)
- {
- switch (type)
- {
+{
+ switch (type) {
case EVP_MD_CTRL_MICALG:
- {
- *((char **)ptr) = OPENSSL_malloc(strlen(micalg_256)+1);
- if (*((char **)ptr) != NULL)
{
- strcpy(*((char **)ptr), micalg_256);
- return 1;
+ *((char **)ptr) = OPENSSL_malloc(strlen(micalg_256) + 1);
+ if (*((char **)ptr) != NULL) {
+ strcpy(*((char **)ptr), micalg_256);
+ return 1;
+ }
+ return 0;
}
- return 0;
- }
default:
- return 0;
+ return 0;
}
- }
+}
static int gost_digest_ctrl_512(EVP_MD_CTX *ctx, int type, int arg, void *ptr)
- {
- switch (type)
- {
+{
+ switch (type) {
case EVP_MD_CTRL_MICALG:
- {
- *((char **)ptr) = OPENSSL_malloc(strlen(micalg_512)+1);
- if (*((char **)ptr) != NULL)
{
- strcpy(*((char **)ptr), micalg_512);
- return 1;
+ *((char **)ptr) = OPENSSL_malloc(strlen(micalg_512) + 1);
+ if (*((char **)ptr) != NULL) {
+ strcpy(*((char **)ptr), micalg_512);
+ return 1;
+ }
+ return 0;
}
- return 0;
- }
- return 1;
+ return 1;
default:
- return 0;
+ return 0;
}
- }
-
+}
static int pkey_gost_mac_init(EVP_PKEY_CTX *ctx)
{
struct gost_mac_pmeth_data *data = OPENSSL_malloc(sizeof(*data));
- EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
+ EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
if (!data)
return 0;
memset(data, 0, sizeof(*data));
- data->mac_size = 4;
- data->mac_param_nid = NID_undef;
+ data->mac_size = 4;
+ data->mac_param_nid = NID_undef;
- if (pkey) {
- struct gost_mac_key *key = EVP_PKEY_get0(pkey);
- if (key) {
- data->mac_param_nid = key->mac_param_nid;
- }
- }
+ if (pkey) {
+ struct gost_mac_key *key = EVP_PKEY_get0(pkey);
+ if (key) {
+ data->mac_param_nid = key->mac_param_nid;
+ }
+ }
EVP_PKEY_CTX_set_data(ctx, data);
return 1;
data->key_set = 1;
return 1;
case EVP_PKEY_CTRL_GOST_PARAMSET:
- {
- struct gost_cipher_info *param = p2;
- data->mac_param_nid = param->nid;
- struct gost_mac_key *key = NULL;
- EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
- if (pkey) {
- key = EVP_PKEY_get0(pkey);
- if (key) {
- key->mac_param_nid = param->nid;
- }
- }
- return 1;
- }
+ {
+ struct gost_cipher_info *param = p2;
+ data->mac_param_nid = param->nid;
+ struct gost_mac_key *key = NULL;
+ EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
+ if (pkey) {
+ key = EVP_PKEY_get0(pkey);
+ if (key) {
+ key->mac_param_nid = param->nid;
+ }
+ }
+ return 1;
+ }
case EVP_PKEY_CTRL_DIGESTINIT:
{
EVP_MD_CTX *mctx = p2;
GOST_R_MAC_KEY_NOT_SET);
return 0;
}
- return mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_SET_KEY, 0, key);
+ return mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_SET_KEY, 0,
+ key);
} else {
- return mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_SET_KEY, 32, &(data->key));
+ return mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_SET_KEY, 32,
+ &(data->key));
}
return mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_SET_KEY, 32, key);
}
- case EVP_PKEY_CTRL_MAC_LEN:
- {
- if (p1<1 || p1>8)
- {
-
- GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,GOST_R_INVALID_MAC_SIZE);
- return 0;
- }
- data->mac_size = p1;
- return 1;
- }
+ case EVP_PKEY_CTRL_MAC_LEN:
+ {
+ if (p1 < 1 || p1 > 8) {
+
+ GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_INVALID_MAC_SIZE);
+ return 0;
+ }
+ data->mac_size = p1;
+ return 1;
+ }
}
return -2;
}
return ret;
}
- if (!strcmp(type,maclen_ctrl_string)) {
- char *endptr;
- long size=strtol(value,&endptr,10);
- if (*endptr!='\0') {
- GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR,
- GOST_R_INVALID_MAC_SIZE);
- return 0;
- }
- return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_MAC_LEN,size,NULL);
- }
- if (strcmp(type, param_ctrl_string) == 0)
- {
- ASN1_OBJECT *obj = OBJ_txt2obj(value, 0);
- const struct gost_cipher_info *param = NULL;
- if (obj == NULL) {
- GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR, GOST_R_INVALID_MAC_PARAMS);
- return 0;
- }
-
- param = get_encryption_params(obj);
- if (param == NULL) {
- GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR, GOST_R_INVALID_MAC_PARAMS);
- return 0;
- }
-
- return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_GOST_PARAMSET, 0, (void *)param);
- }
+ if (!strcmp(type, maclen_ctrl_string)) {
+ char *endptr;
+ long size = strtol(value, &endptr, 10);
+ if (*endptr != '\0') {
+ GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR, GOST_R_INVALID_MAC_SIZE);
+ return 0;
+ }
+ return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_MAC_LEN, size, NULL);
+ }
+ if (strcmp(type, param_ctrl_string) == 0) {
+ ASN1_OBJECT *obj = OBJ_txt2obj(value, 0);
+ const struct gost_cipher_info *param = NULL;
+ if (obj == NULL) {
+ GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR, GOST_R_INVALID_MAC_PARAMS);
+ return 0;
+ }
+
+ param = get_encryption_params(obj);
+ if (param == NULL) {
+ GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR, GOST_R_INVALID_MAC_PARAMS);
+ return 0;
+ }
+
+ return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_GOST_PARAMSET, 0,
+ (void *)param);
+ }
return -2;
}
if (keydata == NULL)
return 0;
memcpy(keydata->key, data->key, 32);
- keydata->mac_param_nid = data->mac_param_nid;
+ keydata->mac_param_nid = data->mac_param_nid;
EVP_PKEY_assign(pkey, mac_nid, keydata);
return 1;
}
{
unsigned int tmpsiglen;
int ret;
- struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
+ struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
if (!siglen)
return 0;
return 1;
}
- mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_MAC_LEN, data->mac_size, NULL);
+ mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_MAC_LEN, data->mac_size, NULL);
ret = EVP_DigestFinal_ex(mctx, sig, &tmpsiglen);
*siglen = data->mac_size;
return ret;
while (get_line(check_file, inhash, filename)) {
count++;
if (!hash_file(&ctx, filename, calcsum, open_mode)) {
- errors ++;
- continue;
+ errors++;
+ continue;
}
if (strncmp(calcsum, inhash, 65) == 0) {
if (verbose) {
"%s: %d of %d file(f) failed GOST hash sum check\n",
argv[0], failcount, count);
}
- exit((failcount || errors)? 1 : 0);
+ exit((failcount || errors) ? 1 : 0);
}
if (optind == argc) {
char sum[65];
#ifdef _WIN32
- if (open_mode & O_BINARY) {
- _setmode(fileno(stdin),O_BINARY);
- }
+ if (open_mode & O_BINARY) {
+ _setmode(fileno(stdin), O_BINARY);
+ }
#endif
if (!hash_stream(&ctx, fileno(stdin), sum)) {
perror("stdin");
filename[len] = 0;
memmove(filename, filename + 65, len - 63);
return 1;
- nextline:
+ nextline:
if (verbose)
printf(filename);
}