Esempio n. 1
0
void PSPAKE_Message_generate(PSPAKE_Message *message, PSPAKE_CTX *ctx)
{
    BIGNUM *t1 = BN_new();
    BIGNUM *t2 = BN_new();

    /* just for debugging */
    static int cnt = 0;
    cnt++;

    /* r belongs to [0, q) */
    BN_rand_range(ctx->r, ctx->q);

    /* t1 = g^r mod q */
    BN_mod_exp(t1, ctx->g, ctx->r, ctx->q, ctx->ctx);

    /* t2 = h^secret mod q */
    BN_mod_exp(t2, ctx->h, ctx->secret, ctx->q, ctx->ctx);

    /* ctx->y = t1 * t2 mod q */
    BN_mod_mul(ctx->y, t1, t2, ctx->q, ctx->ctx);

    /* message->y = ctx->y */
    message->y = BN_dup(ctx->y);

    /* print the random number r generated (just for debugging) */
    if (cnt == 1)
    {
        print_bn("alice's r", ctx->r);
    }
    else
    {
        print_bn("bob's r", ctx->r);
    }
}
Esempio n. 2
0
/**
\ingroup Core_Print
\param type
\param skey
*/
void 
ops_print_secret_key_verbose(const ops_content_tag_t type, const ops_secret_key_t* skey)
    {
    printf("------- SECRET KEY or ENCRYPTED SECRET KEY ------\n");
    if(type == OPS_PTAG_CT_SECRET_KEY)
	print_tagname("SECRET_KEY");
    else
	print_tagname("ENCRYPTED_SECRET_KEY");
    //    ops_print_public_key(key);
    printf("S2K Usage: %d\n",skey->s2k_usage);
    if(skey->s2k_usage != OPS_S2KU_NONE)
	{
	printf("S2K Specifier: %d\n",skey->s2k_specifier);
	printf("Symmetric algorithm: %d (%s)\n",skey->algorithm,
	       ops_show_symmetric_algorithm(skey->algorithm));
	printf("Hash algorithm: %d (%s)\n",skey->hash_algorithm,
	       ops_show_hash_algorithm(skey->hash_algorithm));
	if(skey->s2k_specifier != OPS_S2KS_SIMPLE)
	    print_hexdump("Salt",skey->salt,sizeof skey->salt);
	if(skey->s2k_specifier == OPS_S2KS_ITERATED_AND_SALTED)
	    printf("Octet count: %d\n",skey->octet_count);
	print_hexdump("IV",skey->iv,ops_block_size(skey->algorithm));
	}

    /* no more set if encrypted */
    if(type == OPS_PTAG_CT_ENCRYPTED_SECRET_KEY)
	return;

    switch(skey->public_key.algorithm)
	{
    case OPS_PKA_RSA:
	print_bn("d",skey->key.rsa.d);
	print_bn("p",skey->key.rsa.p);
	print_bn("q",skey->key.rsa.q);
	print_bn("u",skey->key.rsa.u);
	break;

    case OPS_PKA_DSA:
	print_bn("x",skey->key.dsa.x);
	break;

    default:
	assert(0);
	}

    if(skey->s2k_usage == OPS_S2KU_ENCRYPTED_AND_HASHED)
	print_hexdump("Checkhash",skey->checkhash,OPS_CHECKHASH_SIZE);
    else
	printf("Checksum: %04x\n",skey->checksum);

    printf("------- end of SECRET KEY or ENCRYPTED SECRET KEY ------\n");
    }
Esempio n. 3
0
void print_ctx(const PSPAKE_CTX *ctx)
{
    print_bn("g", ctx->g);
    print_bn("h", ctx->h);
    print_bn("secret", ctx->secret);
    print_bn("r", ctx->r);
    print_bn("key", ctx->key);
    print_bn("y", ctx->y);
    print_bn("y_", ctx->y_);
}
Esempio n. 4
0
/**
\ingroup Core_Print
\param pkey
*/
void 
ops_print_public_key(const ops_public_key_t *pkey)
    {
    printf("------- PUBLIC KEY ------\n");
    print_unsigned_int("Version",pkey->version);
    print_time("Creation Time", pkey->creation_time);
    if(pkey->version == OPS_V3)
	print_unsigned_int("Days Valid",pkey->days_valid);

    print_string_and_value("Algorithm",ops_show_pka(pkey->algorithm),
			   pkey->algorithm);

    switch(pkey->algorithm)
	{
    case OPS_PKA_DSA:
	print_bn("p",pkey->key.dsa.p);
	print_bn("q",pkey->key.dsa.q);
	print_bn("g",pkey->key.dsa.g);
	print_bn("y",pkey->key.dsa.y);
	break;

    case OPS_PKA_RSA:
    case OPS_PKA_RSA_ENCRYPT_ONLY:
    case OPS_PKA_RSA_SIGN_ONLY:
	print_bn("n",pkey->key.rsa.n);
	print_bn("e",pkey->key.rsa.e);
	break;

    case OPS_PKA_ELGAMAL:
    case OPS_PKA_ELGAMAL_ENCRYPT_OR_SIGN:
	print_bn("p",pkey->key.elgamal.p);
	print_bn("g",pkey->key.elgamal.g);
	print_bn("y",pkey->key.elgamal.y);
	break;

    default:
	assert(0);
	}

    printf("------- end of PUBLIC KEY ------\n");
    }
Esempio n. 5
0
//old
BIGNUM *Egcd(const BIGNUM *n, const BIGNUM *m, BIGNUM *x, BIGNUM *y)
	{
		//print_bn("n", n);
		//print_bn("m", m);
		
	BIGNUM *value = BN_new();
	BIGNUM *temp = BN_new();
	BIGNUM *t1 = BN_new();
	BIGNUM *t2 = BN_new();
	BIGNUM *new_m = BN_new();
	BN_CTX *ctx = BN_CTX_new();
	
	if (BN_is_zero(m))
		{
		BN_set_word(x, 1);
		BN_set_word(y, 0);
		value = BN_dup(n);
		
		//print_bn("x", x);
		//print_bn("y", y);
	
		return value;
		}	
		
	BN_mod(new_m, n, m, ctx);
	//printf("called once\n");
	value = BN_dup(Egcd(m, new_m, x, y));
	
	print_bn("n", n);
	print_bn("m", m);
	print_bn("old_x", x);
	print_bn("old_y", y);
	
	temp = BN_dup(x);
	
	x = BN_dup(y);
	
	/* y = temp - (n/m) * y */
	BN_div(t1, NULL, n, m, ctx);
	BN_mul(t2, t1, y, ctx);
	BN_sub(y, temp, t2);
	
	print_bn("x", x);
	print_bn("y", y);
	
	return value;
	}