permute_args(int panonopt_start, int panonopt_end, int opt_end,
char * const *nargv)
{
- int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
+ int cyclelen, i, j, ncycle, nnonopts, nopts;
char *swap;
/*
cyclelen = (opt_end - panonopt_start) / ncycle;
for (i = 0; i < ncycle; i++) {
- cstart = panonopt_end+i;
- pos = cstart;
+ int cstart = panonopt_end+i;
+ int pos = cstart;
for (j = 0; j < cyclelen; j++) {
if (pos >= panonopt_end)
pos -= nnonopts;
/* Store parameters into ASN1 structure */
int gost89_get_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
{
- int ret = -1;
int len;
GOST_CIPHER_PARAMS *gcp = NULL;
unsigned char *p;
int nid;
if (ASN1_TYPE_get(params) != V_ASN1_SEQUENCE) {
- return ret;
+ return -1;
}
p = params->value.sequence->data;
{
struct ossl_gost_imit_ctx *c = EVP_MD_CTX_md_data(ctx);
const unsigned char *p = data;
- size_t bytes = count, i;
+ size_t bytes = count;
if (!(c->key_set)) {
GOSTerr(GOST_F_GOST_IMIT_UPDATE, GOST_R_MAC_KEY_NOT_SET);
return 0;
}
if (c->bytes_left) {
+ size_t i;
for (i = c->bytes_left; i < 8 && bytes > 0; bytes--, i++, p++) {
c->partial_block[i] = *p;
}
bool encrypting = (bool) EVP_CIPHER_CTX_encrypting(ctx);
const unsigned char *current_in = in;
unsigned char *current_out = out;
- grasshopper_w128_t *currentInputBlock;
- grasshopper_w128_t *currentOutputBlock;
size_t blocks = inl / GRASSHOPPER_BLOCK_SIZE;
size_t i;
grasshopper_w128_t *currentBlock;
for (i = 0; i < blocks;
i++, current_in += GRASSHOPPER_BLOCK_SIZE, current_out +=
GRASSHOPPER_BLOCK_SIZE) {
- currentInputBlock = (grasshopper_w128_t *) current_in;
- currentOutputBlock = (grasshopper_w128_t *) current_out;
+ grasshopper_w128_t *currentInputBlock = (grasshopper_w128_t *) current_in;
+ grasshopper_w128_t *currentOutputBlock = (grasshopper_w128_t *) current_out;
if (encrypting) {
grasshopper_append128(currentBlock, currentInputBlock);
grasshopper_encrypt_block(&c->encrypt_round_keys, currentBlock,
void inc_counter(unsigned char *counter, size_t counter_bytes)
{
- unsigned char c;
unsigned int n = counter_bytes;
do {
+ unsigned char c;
--n;
c = counter[n];
++c;
*ctx, ASN1_TYPE
*params)
{
- int ret = -1;
-
if (ASN1_TYPE_get(params) != V_ASN1_SEQUENCE) {
- return ret;
+ return -1;
}
return 1;
#include "gost_grasshopper_defines.h"
static GRASSHOPPER_INLINE void grasshopper_l(grasshopper_w128_t* w) {
- uint8_t x;
- unsigned int j;
- int i;
+ unsigned int j;
+ int i;
// 16 rounds
for (j = 0; j < sizeof(grasshopper_lvec) / sizeof(grasshopper_lvec[0]); j++) {
+ uint8_t x;
// An LFSR with 16 elements from GF(2^8)
x = w->b[15]; // since lvec[15] = 1
}
static GRASSHOPPER_INLINE void grasshopper_l_inv(grasshopper_w128_t* w) {
- uint8_t x;
- unsigned int j;
- int i;
+ unsigned int j;
+ int i;
// 16 rounds
for (j = 0; j < sizeof(grasshopper_lvec) / sizeof(grasshopper_lvec[0]); j++) {
-
- x = w->b[0];
+ uint8_t x = w->b[0];
for (i = 0; i < 15; i++) {
w->b[i] = w->b[i + 1];
x ^= grasshopper_galois_mul(w->b[i], grasshopper_lvec[i]);
void grasshopper_set_encrypt_key(grasshopper_round_keys_t* subkeys, const grasshopper_key_t* key) {
grasshopper_w128_t c, x, y, z;
- int i;
+ int i;
for (i = 0; i < 16; i++) {
// this will be have to changed for little-endian systems
void keyDiversifyCryptoPro(gost_ctx * ctx, const unsigned char *inputKey,
const unsigned char *ukm, unsigned char *outputKey)
{
-
- u4 k, s1, s2;
- int i, j, mask;
- unsigned char S[8];
+ int i;
memcpy(outputKey, inputKey, 32);
for (i = 0; i < 8; i++) {
+ u4 s1 = 0;
+ u4 s2 = 0;
+ int j, mask;
+ unsigned char S[8];
/* Make array of integers from key */
/* Compute IV S */
- s1 = 0, s2 = 0;
for (j = 0, mask = 1; j < 8; j++, mask <<= 1) {
+ u4 k;
k = ((u4) outputKey[4 * j]) | (outputKey[4 * j + 1] << 8) |
(outputKey[4 * j + 2] << 16) | (outputKey[4 * j + 3] << 24);
if (mask & ukm[i]) {
static int pkey_gost_ec_ctrl_str_256(EVP_PKEY_CTX *ctx,
const char *type, const char *value)
{
- int param_nid = 0;
-
if (strcmp(type, param_ctrl_string) == 0) {
+ int param_nid = 0;
+
if (!value) {
return 0;
}
default:
return 0;
}
- } else if ((strlen(value) == 3)
- && (toupper((unsigned char)value[0]) == 'T')
- && (toupper((unsigned char)value[1]) == 'C')) {
+ } else if ((strlen(value) == 3)
+ && (toupper((unsigned char)value[0]) == 'T')
+ && (toupper((unsigned char)value[1]) == 'C')) {
switch (toupper((unsigned char)value[2])) {
case 'A':
param_nid = NID_id_tc26_gost_3410_2012_256_paramSetA;
case EVP_PKEY_CTRL_DIGESTINIT:
{
EVP_MD_CTX *mctx = p2;
- struct gost_mac_key *key;
if (!data->key_set) {
+ struct gost_mac_key *key;
EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
if (!pkey) {
GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,
case EVP_PKEY_CTRL_DIGESTINIT:
{
EVP_MD_CTX *mctx = p2;
- struct gost_mac_key *key;
if (!data->key_set) {
+ struct gost_mac_key *key;
EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
if (!pkey) {
GOSTerr(GOST_F_PKEY_GOST_OMAC_CTRL,
{
int i;
int carry = 0;
- int sum;
for (i = 0; i < n; i++) {
- sum = (int)left[i] + (int)right[i] + carry;
+ int sum = (int)left[i] + (int)right[i] + carry;
left[i] = sum & 0xff;
carry = sum >> 8;
}
void gost2012_hash_block(gost2012_hash_ctx * CTX,
const unsigned char *data, size_t len)
{
- register size_t chunksize;
register size_t bufsize = CTX->bufsize;
if (bufsize == 0) {
}
while (len) {
- chunksize = 64 - bufsize;
+ register size_t chunksize = 64 - bufsize;
if (chunksize > len)
chunksize = len;