コード例 #1
0
ファイル: rsa.c プロジェクト: AustinHunting/krypton
/**
 * Used for diagnostics.
 */
void RSA_print(const RSA_CTX *rsa_ctx) {
  if (rsa_ctx == NULL) return;

  printf("-----------------   RSA DEBUG   ----------------\n");
  printf("Size:\t%d\n", rsa_ctx->num_octets);
  bi_print("Modulus", rsa_ctx->m);
  bi_print("Public Key", rsa_ctx->e);
  bi_print("Private Key", rsa_ctx->d);
}
コード例 #2
0
ファイル: bitest.c プロジェクト: wtaysom/tau
void test_seq(int n)
{
	BiTree_s tree = { 0 };
	Rec_s rec;
	unint i;

	if (FALSE) seed_random();
	for (i = 0; i < n; i++) {
		rec.key = seq_lump();
		rec.val = rnd_lump();
		bi_insert(&tree, rec);
	}
	bi_print(&tree);
}
コード例 #3
0
ファイル: bi.c プロジェクト: berte/mediaplayer
BI *init_BI(void)
{
	BI *p;
	
	p = (BI *) bi_osal_malloc(sizeof(BI));
	if (p == NULL) {
		bi_print("init_BI error!\n");
		return NULL;
	}
	
	memset(p, 0, sizeof(BI));
	p->m_nSign=1;
	p->m_nLength=1;

	return p;
}
コード例 #4
0
ファイル: main.c プロジェクト: seppo0010/Euler
int main() {
	bi_initialize();
	bigint sum = int_to_bi(1);
	bigint last = int_to_bi(1);
	int i, j;
	for (i = 1; i <= (SIZE-1)/2; ++i) {
		for (j = 0; j < 4; ++j) {
			last = bi_add(last, bi_int_multiply(int_to_bi(i), 2));
			sum = bi_add(sum, bi_copy(last));
		}
	}
	bi_print(stdout, sum);
	printf("\n");
	bi_free(last);
	bi_terminate();
	return 0;
}
コード例 #5
0
ファイル: rsa.c プロジェクト: tomatoXu/syslinux-rsa-test
/**
 * Use PKCS1.5 for encryption/signing.
 * see http://www.rsasecurity.com/rsalabs/node.asp?id=2125
 */
int RSA_encrypt(const RSA_CTX *ctx, const uint8_t *in_data, uint16_t in_len, 
        uint8_t *out_data, int is_signing)
{
    int byte_size = ctx->num_octets;printf("byte_size:%d\n",byte_size);
    int num_pads_needed = byte_size-in_len-3;printf("num_pads_needed:%d\n",num_pads_needed);
    bigint *dat_bi, *encrypt_bi;

    /* note: in_len+11 must be > byte_size */
    out_data[0] = 0;     /* ensure encryption block is < modulus */
    if (is_signing)
    {
        out_data[1] = 1;        /* PKCS1.5 signing pads with "0xff"'s */
        memset(&out_data[2], 0xff, num_pads_needed);
    }
    else /* randomize the encryption padding with non-zero bytes */   
    {    
        out_data[1] = 2;
        get_random_NZ(num_pads_needed, &out_data[2]);
    }
    out_data[2+num_pads_needed] = 0;

    memcpy(&out_data[3+num_pads_needed], in_data, in_len);

    /* now encrypt it */
    dat_bi = bi_import(ctx->bi_ctx, out_data, byte_size);
           bi_print("pre_dispose_data",dat_bi);
    encrypt_bi = is_signing ? RSA_private(ctx, dat_bi) : 
        RSA_public(ctx, dat_bi);
        
    bi_export(ctx->bi_ctx, encrypt_bi, out_data, byte_size);
        int i=0;
        printf("encrypted message in uint8_t:");
        for (i;i<byte_size;i++)
                printf("0x%02x ",out_data[i]);
        printf("\n\n");
        
    return byte_size;
}
コード例 #6
0
ファイル: x509.c プロジェクト: cottsak/axtls-8266
void x509_print(const X509_CTX *cert, CA_CERT_CTX *ca_cert_ctx)
{
    if (cert == NULL)
        return;

    printf("=== CERTIFICATE ISSUED TO ===\n");
    printf("Common Name (CN):\t\t");
    printf("%s\n", cert->cert_dn[X509_COMMON_NAME] ?
           cert->cert_dn[X509_COMMON_NAME] : not_part_of_cert);

    printf("Organization (O):\t\t");
    printf("%s\n", cert->cert_dn[X509_ORGANIZATION] ?
           cert->cert_dn[X509_ORGANIZATION] : not_part_of_cert);

    printf("Organizational Unit (OU):\t");
    printf("%s\n", cert->cert_dn[X509_ORGANIZATIONAL_UNIT] ?
           cert->cert_dn[X509_ORGANIZATIONAL_UNIT] : not_part_of_cert);

    printf("=== CERTIFICATE ISSUED BY ===\n");
    printf("Common Name (CN):\t\t");
    printf("%s\n", cert->ca_cert_dn[X509_COMMON_NAME] ?
           cert->ca_cert_dn[X509_COMMON_NAME] : not_part_of_cert);

    printf("Organization (O):\t\t");
    printf("%s\n", cert->ca_cert_dn[X509_ORGANIZATION] ?
           cert->ca_cert_dn[X509_ORGANIZATION] : not_part_of_cert);

    printf("Organizational Unit (OU):\t");
    printf("%s\n", cert->ca_cert_dn[X509_ORGANIZATIONAL_UNIT] ?
           cert->ca_cert_dn[X509_ORGANIZATIONAL_UNIT] : not_part_of_cert);

    printf("Not Before:\t\t\t%s", ctime(&cert->not_before));
    printf("Not After:\t\t\t%s", ctime(&cert->not_after));
    printf("RSA bitsize:\t\t\t%d\n", cert->rsa_ctx->num_octets*8);
    printf("Sig Type:\t\t\t");
    switch (cert->sig_type)
    {
    case SIG_TYPE_MD5:
        printf("MD5\n");
        break;
    case SIG_TYPE_SHA1:
        printf("SHA1\n");
        break;
    case SIG_TYPE_MD2:
        printf("MD2\n");
        break;
    default:
        printf("Unrecognized: %d\n", cert->sig_type);
        break;
    }

    if (ca_cert_ctx)
    {
        printf("Verify:\t\t\t\t%s\n",
               x509_display_error(x509_verify(ca_cert_ctx, cert)));
    }

#if 0
    print_blob("Signature", cert->signature, cert->sig_len);
    bi_print("Modulus", cert->rsa_ctx->m);
    bi_print("Pub Exp", cert->rsa_ctx->e);
#endif

    if (ca_cert_ctx)
    {
        x509_print(cert->next, ca_cert_ctx);
    }

    TTY_FLUSH();
}
コード例 #7
0
ファイル: main.c プロジェクト: seppo0010/Euler
int main() {
	bi_initialize();
	bigint sum = int_to_bi(0);
	int a,b,c,d,e,f,g,h,i,j;
	int n;
	for (a=9;a>0;--a) {
	for (b=9;b>=0;--b) {
		if (b==a) continue;
	for (c=9;c>=0;--c) {
		if (c==a||c==b) continue;
	for (d=9;d>=0;--d) {
		if (d==a||d==b||d==c) continue;
	for (e=9;e>=0;--e) {
		if (e==a||e==b||e==c||e==d) continue;
	for (f=9;f>=0;--f) {
		if (f==a||f==b||f==c||f==d||f==e) continue;
	for (g=9;g>=0;--g) {
		if (g==a||g==b||g==c||g==d||g==e||g==f) continue;
	for (h=9;h>=0;--h) {
		if (h==a||h==b||h==c||h==d||h==e||h==f||h==g) continue;
	for (i=9;i>=0;--i) {
		if (i==a||i==b||i==c||i==d||i==e||i==f||i==g||i==h) continue;
	for (j=9;j>=0;--j) {
		if (j==a||j==b||j==c||j==d||j==e||j==f||j==g||j==h||j==i) continue;
		if ((b * 100 + c * 10 + d) % 2 == 0)
		if ((c * 100 + d * 10 + e) % 3 == 0)
		if ((d * 100 + e * 10 + f) % 5 == 0)
		if ((e * 100 + f * 10 + g) % 7 == 0)
		if ((f * 100 + g * 10 + h) % 11 == 0)
		if ((g * 100 + h * 10 + i) % 13 == 0)
		if ((h * 100 + i * 10 + j) % 17 == 0) {
			n = 
			    b * 100000000 +
			    c * 10000000 +
			    d * 1000000 +
			    e * 100000 +
			    f * 10000 +
			    g * 1000 +
			    h * 100 +
			    i * 10 +
			    j * 1;
			sum = bi_add(sum, int_to_bi(n));
			sum = bi_add(sum, bi_int_multiply(int_to_bi(1000000000), a));
#ifdef DEBUG
printf("%d%d%d%d%d%d%d%d%d%d\n", a,b,c,d,e,f,g,h,i,j);
bi_print(stdout,bi_copy(sum));
printf("\n");
#endif
		}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	bi_print(stdout,sum);
	printf("\n");
	bi_terminate();
	return 0;
}
コード例 #8
0
ファイル: x509.c プロジェクト: slaff/axtls-8266
void x509_print(const X509_CTX *cert, CA_CERT_CTX *ca_cert_ctx) 
{
    if (cert == NULL)
        return;

    printf("=== CERTIFICATE ISSUED TO ===\n");
    printf("Common Name (CN):\t\t");
    printf("%s\n", cert->cert_dn[X509_COMMON_NAME] ?
                    cert->cert_dn[X509_COMMON_NAME] : not_part_of_cert);

    printf("Organization (O):\t\t");
    printf("%s\n", cert->cert_dn[X509_ORGANIZATION] ?
        cert->cert_dn[X509_ORGANIZATION] : not_part_of_cert);

    if (cert->cert_dn[X509_ORGANIZATIONAL_UNIT]) 
    {
        printf("Organizational Unit (OU):\t");
        printf("%s\n", cert->cert_dn[X509_ORGANIZATIONAL_UNIT]);
    }

    if (cert->cert_dn[X509_LOCATION]) 
    {
        printf("Location (L):\t\t\t");
        printf("%s\n", cert->cert_dn[X509_LOCATION]);
    }

    if (cert->cert_dn[X509_COUNTRY]) 
    {
        printf("Country (C):\t\t\t");
        printf("%s\n", cert->cert_dn[X509_COUNTRY]);
    }

    if (cert->cert_dn[X509_STATE]) 
    {
        printf("State (ST):\t\t\t");
        printf("%s\n", cert->cert_dn[X509_STATE]);
    }

    if (cert->basic_constraint_present)
    {
        printf("Basic Constraints:\t\t%sCA:%s, pathlen:%d\n",
                cert->basic_constraint_is_critical ? 
                    "critical, " : "",
                cert->basic_constraint_cA? "TRUE" : "FALSE",
                cert->basic_constraint_pathLenConstraint);
    }

    if (cert->key_usage_present)
    {
        printf("Key Usage:\t\t\t%s", cert->key_usage_is_critical ? 
                    "critical, " : "");
        bool has_started = false;

        if (IS_SET_KEY_USAGE_FLAG(cert, KEY_USAGE_DIGITAL_SIGNATURE))
        {
            printf("Digital Signature");
            has_started = true;
        }

        if (IS_SET_KEY_USAGE_FLAG(cert, KEY_USAGE_NON_REPUDIATION))
        {
            if (has_started)
                printf(", ");

            printf("Non Repudiation");
            has_started = true;
        }

        if (IS_SET_KEY_USAGE_FLAG(cert, KEY_USAGE_KEY_ENCIPHERMENT))
        {
            if (has_started)
                printf(", ");

            printf("Key Encipherment");
            has_started = true;
        }
        
        if (IS_SET_KEY_USAGE_FLAG(cert, KEY_USAGE_DATA_ENCIPHERMENT))
        {
            if (has_started)
                printf(", ");

            printf("Data Encipherment");
            has_started = true;
        }

        if (IS_SET_KEY_USAGE_FLAG(cert, KEY_USAGE_KEY_AGREEMENT))
        {
            if (has_started)
                printf(", ");

            printf("Key Agreement");
            has_started = true;
        }

        if (IS_SET_KEY_USAGE_FLAG(cert, KEY_USAGE_KEY_CERT_SIGN))
        {
            if (has_started)
                printf(", ");

            printf("Key Cert Sign");
            has_started = true;
        }

        if (IS_SET_KEY_USAGE_FLAG(cert, KEY_USAGE_CRL_SIGN))
        {
            if (has_started)
                printf(", ");

            printf("CRL Sign");
            has_started = true;
        }
       
        if (IS_SET_KEY_USAGE_FLAG(cert, KEY_USAGE_ENCIPHER_ONLY))
        {
            if (has_started)
                printf(", ");

            printf("Encipher Only");
            has_started = true;
        }

        if (IS_SET_KEY_USAGE_FLAG(cert, KEY_USAGE_DECIPHER_ONLY))
        {
            if (has_started)
                printf(", ");

            printf("Decipher Only");
            has_started = true;
        }

        printf("\n");
    }

    if (cert->subject_alt_name_present)
    {
        printf("Subject Alt Name:\t\t%s", cert->subject_alt_name_is_critical 
                ?  "critical, " : "");
        if (cert->subject_alt_dnsnames)
        {
            int i = 0;

            while (cert->subject_alt_dnsnames[i])
                printf("%s ", cert->subject_alt_dnsnames[i++]);
        }
        printf("\n");

    }

    printf("=== CERTIFICATE ISSUED BY ===\n");
    printf("Common Name (CN):\t\t");
    printf("%s\n", cert->ca_cert_dn[X509_COMMON_NAME] ?
                    cert->ca_cert_dn[X509_COMMON_NAME] : not_part_of_cert);

    printf("Organization (O):\t\t");
    printf("%s\n", cert->ca_cert_dn[X509_ORGANIZATION] ?
        cert->ca_cert_dn[X509_ORGANIZATION] : not_part_of_cert);

    if (cert->ca_cert_dn[X509_ORGANIZATIONAL_UNIT]) 
    {
        printf("Organizational Unit (OU):\t");
        printf("%s\n", cert->ca_cert_dn[X509_ORGANIZATIONAL_UNIT]);
    }

    if (cert->ca_cert_dn[X509_LOCATION]) 
    {
        printf("Location (L):\t\t\t");
        printf("%s\n", cert->ca_cert_dn[X509_LOCATION]);
    }

    if (cert->ca_cert_dn[X509_COUNTRY]) 
    {
        printf("Country (C):\t\t\t");
        printf("%s\n", cert->ca_cert_dn[X509_COUNTRY]);
    }

    if (cert->ca_cert_dn[X509_STATE]) 
    {
        printf("State (ST):\t\t\t");
        printf("%s\n", cert->ca_cert_dn[X509_STATE]);
    }

    printf("Not Before:\t\t\t%s", ctime(&cert->not_before));
    printf("Not After:\t\t\t%s", ctime(&cert->not_after));
    printf("RSA bitsize:\t\t\t%d\n", cert->rsa_ctx->num_octets*8);
    printf("Sig Type:\t\t\t");
    switch (cert->sig_type)
    {
        case SIG_TYPE_MD5:
            printf("MD5\n");
            break;
        case SIG_TYPE_SHA1:
            printf("SHA1\n");
            break;
        case SIG_TYPE_SHA256:
            printf("SHA256\n");
            break;
        case SIG_TYPE_SHA384:
            printf("SHA384\n");
            break;
        case SIG_TYPE_SHA512:
            printf("SHA512\n");
            break;
        default:
            printf("Unrecognized: %d\n", cert->sig_type);
            break;
    }

    if (ca_cert_ctx)
    {
        int pathLenConstraint = 0;
        char buff[64];
        printf("Verify:\t\t\t\t%s\n",
                x509_display_error(x509_verify(ca_cert_ctx, cert,
                        &pathLenConstraint), buff));
    }

#if 0
    print_blob("Signature", cert->signature, cert->sig_len);
    bi_print("Modulus", cert->rsa_ctx->m);
    bi_print("Pub Exp", cert->rsa_ctx->e);
#endif

    if (ca_cert_ctx)
    {
        x509_print(cert->next, ca_cert_ctx);
    }

    TTY_FLUSH();
}