当前位置: 首页>>代码示例>>C++>>正文


C++ DES_set_odd_parity函数代码示例

本文整理汇总了C++中DES_set_odd_parity函数的典型用法代码示例。如果您正苦于以下问题:C++ DES_set_odd_parity函数的具体用法?C++ DES_set_odd_parity怎么用?C++ DES_set_odd_parity使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了DES_set_odd_parity函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: perf

int perf()
{
        DES_cblock key1, key2, key3, iv;
        DES_key_schedule ks1, ks2, ks3;

        char* payload = (char*)malloc(64);
        int i;
        uint64_t start, end;

       	memcpy(payload, "hello world hello world hello world\n", 64);
 
	// 1. Key & IV Extract
        memcpy(key1, "aeaeaeae", 8);
        memcpy(key2, "aeaeaeae", 8);
        memcpy(key3, "aeaeaeae", 8);

        memcpy(iv, "aeaeaeae", 8);

        DES_set_odd_parity(&key1);
        DES_set_odd_parity(&key2);
        DES_set_odd_parity(&key3);

        // Key Validation Check
        if(DES_set_key_checked(&key1, &ks1) ||
           DES_set_key_checked(&key2, &ks2) ||
           DES_set_key_checked(&key3, &ks3))
        {
               printf("DES_set_key_checked Error\n");
        }
          
        start = cpu_tsc();

        for(i = 0; i < 1000000; i++)
        {       
                DES_ede3_cbc_encrypt((const unsigned char*)payload,
                                (unsigned char*)payload, 
                                64 , &ks1, &ks2, &ks3, &iv, DES_ENCRYPT);       
        }

        end = cpu_tsc();
	
        printf("encrpytion time : %ld\n", (end-start)/10000);
	
	start = cpu_tsc();

        for(i = 0; i < 1000000; i++)
        {
                DES_ede3_cbc_encrypt((const unsigned char*)payload,
                                (unsigned char*)payload,
                                64 , &ks1, &ks2, &ks3, &iv, DES_DECRYPT);
        }

        end = cpu_tsc();

        printf("decryption time : %ld\n", (end-start)/10000);

	return 0;
}
开发者ID:carriercomm,项目名称:ipsec-1,代码行数:58,代码来源:test_linux.c

示例2: DES3_random_key

static void
DES3_random_key(krb5_context context,
                krb5_keyblock *key)
{
    DES_cblock *k = key->keyvalue.data;
    do {
        krb5_generate_random_block(k, 3 * sizeof(DES_cblock));
        DES_set_odd_parity(&k[0]);
        DES_set_odd_parity(&k[1]);
        DES_set_odd_parity(&k[2]);
    } while(DES_is_weak_key(&k[0]) ||
            DES_is_weak_key(&k[1]) ||
            DES_is_weak_key(&k[2]));
}
开发者ID:randombit,项目名称:hacrypto,代码行数:14,代码来源:crypto-des3.c

示例3: des3_init

enum cryptoerr
des3_init(struct keystate *ks, u_int8_t *key, u_int16_t len)
{
	DES_set_odd_parity((void *)key);
	DES_set_odd_parity((void *)(key + 8));
	DES_set_odd_parity((void *)(key + 16));

	/* As of the draft Tripe-DES does not check for weak keys */
	DES_set_key((void *)key, &ks->ks_des[0]);
	DES_set_key((void *)(key + 8), &ks->ks_des[1]);
	DES_set_key((void *)(key + 16), &ks->ks_des[2]);

	return EOKAY;
}
开发者ID:SylvestreG,项目名称:bitrig,代码行数:14,代码来源:crypto.c

示例4: des3_set_key

static int des3_set_key(struct ssh_cipher_struct *cipher, void *key,void *IV) {
  if (cipher->key == NULL) {
    if (alloc_key(cipher) < 0) {
      return -1;
    }

    DES_set_odd_parity(key);
    DES_set_odd_parity((void*)((uint8_t*)key + 8));
    DES_set_odd_parity((void*)((uint8_t*)key + 16));
    DES_set_key_unchecked(key, cipher->key);
    DES_set_key_unchecked((void*)((uint8_t*)key + 8), (void*)((uint8_t*)cipher->key + sizeof(DES_key_schedule)));
    DES_set_key_unchecked((void*)((uint8_t*)key + 16), (void*)((uint8_t*)cipher->key + 2 * sizeof(DES_key_schedule)));
  }
  cipher->IV=IV;
  return 0;
}
开发者ID:SHLD,项目名称:node-libssh,代码行数:16,代码来源:libcrypto.c

示例5: _krb5_DES3_random_to_key

void
_krb5_DES3_random_to_key(krb5_context context,
                         krb5_keyblock *key,
                         const void *data,
                         size_t size)
{
    unsigned char *x = key->keyvalue.data;
    const u_char *q = data;
    DES_cblock *k;
    int i, j;

    memset(key->keyvalue.data, 0, key->keyvalue.length);
    for (i = 0; i < 3; ++i) {
        unsigned char foo;
        for (j = 0; j < 7; ++j) {
            unsigned char b = q[7 * i + j];

            x[8 * i + j] = b;
        }
        foo = 0;
        for (j = 6; j >= 0; --j) {
            foo |= q[7 * i + j] & 1;
            foo <<= 1;
        }
        x[8 * i + 7] = foo;
    }
    k = key->keyvalue.data;
    for (i = 0; i < 3; i++) {
        DES_set_odd_parity(&k[i]);
        if(DES_is_weak_key(&k[i]))
            _krb5_xor(&k[i], (const unsigned char*)"\0\0\0\0\0\0\0\xf0");
    }
}
开发者ID:randombit,项目名称:hacrypto,代码行数:33,代码来源:crypto-des3.c

示例6: openssl_des_crypt

void openssl_des_crypt()
{
	int size;
	DES_cblock key;
	DES_cblock outputs;
	const_DES_cblock inputs;
	DES_key_schedule schedule;
	unsigned char tmp[16] = "des crypt";

	DES_random_key(&key);
	DES_string_to_key("beike2012", &key);
	DES_set_odd_parity(&key);
	des_check_key_parity(&key);
	DES_set_key_checked(&key, &schedule);
	DES_is_weak_key((const_DES_cblock *)tmp);
	DES_ecb_encrypt((const_DES_cblock *)tmp, &outputs, &schedule, DES_ENCRYPT);
	printf("\nDES_ecb_encrypt(%s) = ", tmp);
	for (size = 0; size < sizeof(outputs); size++)
		printf("%02x", outputs[size]);
	printf("\n");

	DES_ecb_encrypt(&outputs, &inputs, &schedule, DES_DECRYPT);
	printf("DES_ecb_decrypt(");
	for (size = 0; size < sizeof(outputs); size++)
		printf("%02x", outputs[size]);
	printf(") = %s\n", inputs);
}
开发者ID:beike2020,项目名称:source,代码行数:27,代码来源:openssl_base.c

示例7: set_des_key

/*
 * This sets the DES key and (if you're using the deszip version)
 * the direction of the transformation.  This uses the Sun
 * to map the 64-bit key onto the 56 bits that the key schedule
 * generation routines use: the old way, which just uses the user-
 * supplied 64 bits as is, and the new way, which resets the parity
 * bit to be the same as the low-order bit in each character.  The
 * new way generates a greater variety of key schedules, since many
 * systems set the parity (high) bit of each character to 0, and the
 * DES ignores the low order bit of each character.
 */
void
set_des_key(DES_cblock *buf)		/* key block */
{
	int i, j;			/* counter in a for loop */
	int par;			/* parity counter */

	/*
	 * if the parity is not preserved, flip it
	 */
	if (!pflag) {
		for (i = 0; i < 8; i++) {
			par = 0;
			for (j = 1; j < 8; j++)
				if ((bits[j] & (*buf)[i]) != 0)
					par++;
			if ((par & 0x01) == 0x01)
				(*buf)[i] &= 0x7f;
			else
				(*buf)[i] = ((*buf)[i] & 0x7f) | 0x80;
		}
	}

	DES_set_odd_parity(buf);
	DES_set_key(buf, &schedule);
}
开发者ID:jorisgio,项目名称:DragonFlyBSD,代码行数:36,代码来源:cbc.c

示例8: rxkad_derive_des_key

/**
 * Use NIST SP800-108 with HMAC(MD5) in counter mode as the PRF to derive a
 * des key from another type of key.
 *
 * L is 64, as we take 64 random bits and turn them into a 56-bit des key.
 * The output of hmac_md5 is 128 bits; we take the first 64 only, so n
 * properly should be 1.  However, we apply a slight variation due to the
 * possibility of producing a weak des key.  If the output key is weak, do NOT
 * simply correct it, instead, the counter is advanced and the next output
 * used.  As such, we code so as to have n be the full 255 permitted by our
 * encoding of the counter i in an 8-bit field.  L itself is encoded as a
 * 32-bit field, big-endian.  We use the constant string "rxkad" as a label
 * for this key derivation, the standard NUL byte separator, and omit a
 * key-derivation context.  The input key is unique to the krb5 service ticket,
 * which is unlikely to be used in an other location.  If it is used in such
 * a fashion, both locations will derive the same des key from the PRF, but
 * this is no different from if a krb5 des key had been used in the same way,
 * as traditional krb5 rxkad uses the ticket session key directly as the token
 * key.
 *
 * @param[in]  in      pointer to input key data
 * @param[in]  insize  length of input key data
 * @param[out] out     8-byte buffer to hold the derived key
 *
 * @return Returns 0 to indicate success, or an error code.
 *
 * @retval KRB5DES_WEAK_KEY  Successive derivation attempts with all
 * 255 possible counter values each produced weak DES keys.  This input
 * cannot be used to produce a usable key.
 */
static int
rxkad_derive_des_key(const void *in, size_t insize, char out[8])
{
    unsigned char i;
    static unsigned char label[] = "rxkad";
    /* bits of output, as 32 bit word, MSB first */
    static unsigned char Lbuf[4] = { 0, 0, 0, 64 };
    /* only needs to be 16 for md5, but lets be sure it fits */
    unsigned char tmp[64];
    unsigned int mdsize;
    DES_cblock ktmp;
    HMAC_CTX mctx;

    /* stop when 8 bit counter wraps to 0 */
    for (i = 1; i; i++) {
	HMAC_CTX_init(&mctx);
	HMAC_Init_ex(&mctx, in, insize, EVP_md5(), NULL);
	HMAC_Update(&mctx, &i, 1);
	HMAC_Update(&mctx, label, sizeof(label));   /* includes label and separator */
	HMAC_Update(&mctx, Lbuf, 4);
	mdsize = sizeof(tmp);
	HMAC_Final(&mctx, tmp, &mdsize);
	memcpy(ktmp, tmp, 8);
	DES_set_odd_parity(&ktmp);
	if (!DES_is_weak_key(&ktmp)) {
	    memcpy(out, ktmp, 8);
	    return 0;
	}
    }
    return KRB5DES_WEAK_KEY;
}
开发者ID:cg2v,项目名称:heimdal,代码行数:61,代码来源:rxkad_kdf.c

示例9: des3_set_key

static int des3_set_key(struct crypto_struct *cipher, void *key) {
  if (cipher->key == NULL) {
    if (alloc_key(cipher) < 0) {
      return -1;
    }

    DES_set_odd_parity(key);
    DES_set_odd_parity(key + 8);
    DES_set_odd_parity(key + 16);
    DES_set_key_unchecked(key, cipher->key);
    DES_set_key_unchecked(key + 8, cipher->key + sizeof(DES_key_schedule));
    DES_set_key_unchecked(key + 16, cipher->key + 2 * sizeof(DES_key_schedule));
  }

  return 0;
}
开发者ID:BackupTheBerlios,项目名称:libssh-svn,代码行数:16,代码来源:wrapper.c

示例10: des3_set_key

/* 3des cbc for SSH-1 has no suitable EVP construct and requires
 * a custom key setup
 */
static int des3_set_key(struct ssh_cipher_struct *cipher, void *key, void *IV){
    DES_cblock *keys = key;

    DES_set_odd_parity(&keys[0]);
    DES_set_odd_parity(&keys[1]);
    DES_set_odd_parity(&keys[2]);

    cipher->des3_key = malloc(sizeof (struct ssh_3des_key_schedule));
    if (cipher->des3_key == NULL){
        return SSH_ERROR;
    }
    DES_set_key_unchecked(&keys[0], &cipher->des3_key->keys[0]);
    DES_set_key_unchecked(&keys[1], &cipher->des3_key->keys[1]);
    DES_set_key_unchecked(&keys[2], &cipher->des3_key->keys[2]);
    memcpy(cipher->des3_key->ivs.v, IV, 24);
    return SSH_OK;
}
开发者ID:codinn,项目名称:libssh,代码行数:20,代码来源:libcrypto.c

示例11: DES_random_key

int DES_random_key(DES_cblock *ret)
{
    do {
        if (RAND_bytes((unsigned char *)ret, sizeof(DES_cblock)) != 1)
            return (0);
    } while (DES_is_weak_key(ret));
    DES_set_odd_parity(ret);
    return (1);
}
开发者ID:NickAger,项目名称:elm-slider,代码行数:9,代码来源:rand_key.c

示例12: DES_new_random_key

int HC_DEPRECATED
DES_new_random_key(DES_cblock *key)
{
    do {
	if (RAND_bytes(key, sizeof(*key)) != 1)
	    return 1;
	DES_set_odd_parity(key);
    } while(DES_is_weak_key(key));

    return(0);
}
开发者ID:tombibsd,项目名称:netbsd-src,代码行数:11,代码来源:rnd_keys.c

示例13: des1_set_key

static int des1_set_key(struct ssh_cipher_struct *cipher, void *key, void *IV){
  if(!cipher->key){
    if (alloc_key(cipher) < 0) {
      return -1;
    }
    DES_set_odd_parity(key);
    DES_set_key_unchecked(key,cipher->key);
  }
  cipher->IV=IV;
  return 0;
}
开发者ID:SHLD,项目名称:node-libssh,代码行数:11,代码来源:libcrypto.c

示例14: des3_ctrl

static int des3_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
	{

	DES_cblock *deskey = ptr;

	switch(type)
		{
	case EVP_CTRL_RAND_KEY:
		if (RAND_bytes(ptr, c->key_len) <= 0)
			return 0;
		DES_set_odd_parity(deskey);
		if (c->key_len >= 16)
			DES_set_odd_parity(deskey + 1);
		if (c->key_len >= 24)
			DES_set_odd_parity(deskey + 2);
		return 1;

	default:
		return -1;
		}
	}
开发者ID:alisw,项目名称:alice-openssl,代码行数:21,代码来源:e_des3.c

示例15: des1_init

enum cryptoerr
des1_init(struct keystate *ks, u_int8_t *key, u_int16_t len)
{
	/* DES_set_key returns -1 for parity problems, and -2 for weak keys */
	DES_set_odd_parity((void *)key);
	switch (DES_set_key((void *)key, &ks->ks_des[0])) {
	case -2:
		return EWEAKKEY;
	default:
		return EOKAY;
	}
}
开发者ID:SylvestreG,项目名称:bitrig,代码行数:12,代码来源:crypto.c


注:本文中的DES_set_odd_parity函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。