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


C++ AES_decrypt函数代码示例

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


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

示例1: aes_decrypt

void aes_decrypt(struct aes_keys *aes, uchar *buf, int32_t n)
{
	int32_t i;
	for(i = 0; i < n; i += 16)
	{
		AES_decrypt(buf + i, buf + i, &aes->aeskey_decrypt);
	}
}
开发者ID:digrobot,项目名称:oscam,代码行数:8,代码来源:oscam-aes.c

示例2: AES_cbc_encrypt

void
AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
		unsigned long size, const AES_KEY *key,
		unsigned char *iv, int forward_encrypt)
{
    unsigned char tmp[AES_BLOCK_SIZE];
    int i;

    if (forward_encrypt) {
	while (size >= AES_BLOCK_SIZE) {
	    for (i = 0; i < AES_BLOCK_SIZE; i++)
		tmp[i] = in[i] ^ iv[i];
	    AES_encrypt(tmp, out, key);
	    memcpy(iv, out, AES_BLOCK_SIZE);
	    size -= AES_BLOCK_SIZE;
	    in += AES_BLOCK_SIZE;
	    out += AES_BLOCK_SIZE;
	}
	if (size) {
	    for (i = 0; i < size; i++)
		tmp[i] = in[i] ^ iv[i];
	    for (i = size; i < AES_BLOCK_SIZE; i++)
		tmp[i] = iv[i];
	    AES_encrypt(tmp, out, key);
	    memcpy(iv, out, AES_BLOCK_SIZE);
	}
    } else {
	while (size >= AES_BLOCK_SIZE) {
	    memcpy(tmp, in, AES_BLOCK_SIZE);
	    AES_decrypt(tmp, out, key);
	    for (i = 0; i < AES_BLOCK_SIZE; i++)
		out[i] ^= iv[i];
	    memcpy(iv, tmp, AES_BLOCK_SIZE);
	    size -= AES_BLOCK_SIZE;
	    in += AES_BLOCK_SIZE;
	    out += AES_BLOCK_SIZE;
	}
	if (size) {
	    memcpy(tmp, in, AES_BLOCK_SIZE);
	    AES_decrypt(tmp, out, key);
	    for (i = 0; i < size; i++)
		out[i] ^= iv[i];
	    memcpy(iv, tmp, AES_BLOCK_SIZE);
	}
    }
}
开发者ID:DanilKorotenko,项目名称:samba,代码行数:46,代码来源:aes.c

示例3: crypt_dec_block

int crypt_dec_block(cipher_context *cctx, uint8 *in, uint8 *out, int len)
{
	if(len%cctx->block_size)
		return 0;
		
	switch(cctx->alg){
	case ALG_AES_ECB:
	case ALG_AES_CTR:
	{
		int j;

		for(j=0; j<len; j+=cctx->block_size){
			AES_decrypt(in+j, out+j, cctx->enc_ctx);
		}
		return 1;
	}
	case ALG_AES_CBC:
	{
		int i, j;
		uint8 temp[MAX_CIPHER_BLOCK_SIZE];

		for(j=0; j<len; j+=cctx->block_size){
			memcpy(temp, in+j, cctx->block_size);
			AES_decrypt(temp, out+j, cctx->enc_ctx);
			for(i=0; i<cctx->block_size; i++){
				out[j+i]^=cctx->iv[i];
			}
			
			memcpy(cctx->iv, temp, cctx->block_size);
		}
		return 1;
	}
	case ALG_SM4_ECB:
	case ALG_SM4_CTR:
		sm4_crypt_ecb(cctx->enc_ctx, SM4_DECRYPT, len, in, out);
		return 1;
		break;
	case ALG_SM4_CBC:
		sm4_crypt_cbc(cctx->enc_ctx, SM4_DECRYPT, len, cctx->iv, in, out);
		return 1;
		break;
	}
	
	return 0;
}
开发者ID:wqx081,项目名称:mpr_crypto_system,代码行数:45,代码来源:cryptlib.c

示例4: AES_ecb_encrypt

void AES_ecb_encrypt(const unsigned char *in, unsigned char *out,
		     const AES_KEY *key, const int enc) 
{
    assert(in && out && key);
	assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc));

	if (AES_ENCRYPT == enc)
		AES_encrypt(in, out, key);
	else
		AES_decrypt(in, out, key);
}
开发者ID:redmorningcn,项目名称:NC136B-320,代码行数:11,代码来源:aes_ecb.c

示例5: aes_decode

 ustring aes_decode(ustring const& passphrase, ustring const& indata, int length) {
     AES_KEY key;
     AES_set_decrypt_key(passphrase.c_str(), 8 * length, &key);
     unsigned char* outdata = new unsigned char[length];
     AES_decrypt(indata.c_str(), outdata, &key);
     ustring res(outdata, length);
     delete[] outdata;
     return res;
 }
开发者ID:Tsar,项目名称:twofactor_auth,代码行数:9,代码来源:encoding.cpp

示例6: test_xts_aes_decrypt

static void test_xts_aes_decrypt(const void *ctx,
                                 size_t length,
                                 uint8_t *dst,
                                 const uint8_t *src)
{
    const struct TestAES *aesctx = ctx;

    AES_decrypt(src, dst, &aesctx->dec);
}
开发者ID:8tab,项目名称:qemu,代码行数:9,代码来源:test-crypto-xts.c

示例7: cbcdec

int cbcdec(unsigned char* CText, int length){
  unsigned char MBlock[16];
  unsigned char CBlock_cur[16];
  unsigned char CBlock_prev[16];
  unsigned char Key[16];
  int i, j, tmp;
  FILE *fpOut;
  AES_KEY AESkey;

  // This is just for illustration; the actual key used was not the all-0 key!
  Key[0] = Key[1] = Key[2] = Key[3] = 0x00;
  Key[4] = Key[5] = Key[6] = Key[7] = 0x00;
  Key[8] = Key[9] = Key[10] = Key[11] = 0x00;
  Key[12] = Key[13] = Key[14] = Key[15] = 0x00;

  AES_set_decrypt_key((const unsigned char *) Key, 128, &AESkey);

  if (length < 2) return 0;

  for (i=0; i<16; i++)
    CBlock_prev[i] = CText[i];

  j = 1;

  while (j < length) {
    for (i=0; i<16; i++)
      CBlock_cur[i] = CText[16*j+i];

    AES_decrypt((const unsigned char *) CBlock_cur, MBlock, (const AES_KEY *) &AESkey);

    for (i=0; i<16; i++) {
      MBlock[i] ^= CBlock_prev[i];
      // fprintf(fpOut, "%X", MBlock[i]/16), fprintf(fpOut, "%X", MBlock[i]%16);
      // Uncomment this to output the message + the padding for debugging purposes.
      // If we were implementing this for real, we would only output the message
      CBlock_prev[i] = CBlock_cur[i];
    }
    j++;
  }

  j = MBlock[15];
  if ((j==0) || (j>16)) {
   // printf("Error: final byte out of range\n");
    return 0;
  }
  for (i=14; i>=16-j; i--) {
    if (MBlock[i] != j) {
      // printf("Error: incorrect padding\n");
      return 0;
    }
  }

  // printf("Everything fine\n");
  return 1;

}
开发者ID:Jornason,项目名称:Cryptography-Maryland,代码行数:56,代码来源:cbc-decrypt.c

示例8: mz_crypt_aes_decrypt

int32_t mz_crypt_aes_decrypt(void *handle, uint8_t *buf, int32_t size)
{
    mz_crypt_aes *aes = (mz_crypt_aes *)handle;
    if (aes == NULL || buf == NULL)
        return MZ_PARAM_ERROR;
    if (size != MZ_AES_BLOCK_SIZE)
        return MZ_PARAM_ERROR;

    AES_decrypt(buf, buf, &aes->key);
    return size;
}
开发者ID:mschmieder,项目名称:minizip,代码行数:11,代码来源:mz_crypt_openssl.c

示例9: mega_aes_key_decrypt_raw

/**
 * mega_aes_key_decrypt_raw:
 * @aes_key: a #MegaAesKey
 * @cipher: (element-type guint8) (array length=len): Ciphertext
 * @plain: (element-type guint8) (array length=len) (out caller-allocates): Plaintext output data
 * @len: 16 byte aligned length of ciphertext and plaintext data.
 *
 * Decrypt ciphertext blocks using AES key
 */
void mega_aes_key_decrypt_raw(MegaAesKey* aes_key, const guchar* cipher, guchar* plain, gsize len)
{
    gsize off;

    g_return_if_fail(MEGA_IS_AES_KEY(aes_key));
    g_return_if_fail(cipher != NULL);
    g_return_if_fail(plain != NULL);
    g_return_if_fail(len % 16 == 0);

    for (off = 0; off < len; off += 16)
        AES_decrypt(cipher + off, plain + off, &aes_key->priv->dec_key);
}
开发者ID:evandrix,项目名称:megatools,代码行数:21,代码来源:mega-aes-key.c

示例10: __license_decrypt_time

static int __license_decrypt_time(int fd, time_t *_limit)
{
        int ret, cnt;
        time_t limit;
        uint8_t epad[AES_BLOCK_SIZE];
        uint8_t etime[AES_BLOCK_SIZE], etime_hex[LICENSE_AES_HEXLEN];
        AES_KEY key;

        ret = lseek(fd, 0, SEEK_SET);
        if (ret < 0) {
                ret = errno;
                GOTO(err_ret, ret);
        }

        cnt = read(fd, etime_hex, sizeof(etime_hex));
        if (cnt != sizeof(etime_hex)) {
                ret = EIO;
                GOTO(err_ret, ret);
        }

        if (!memcmp(etime_hex, LICENSE_VERSION_2, sizeof(etime_hex))) {
                cnt = pread(fd, etime_hex, sizeof(etime_hex), sizeof(etime_hex) * 2);
                if (cnt != sizeof(etime_hex)) {
                        ret = EIO;
                        GOTO(err_ret, ret);
                }
        }

        if (!__arrcmp(permanent_free, 10, etime_hex, sizeof(etime_hex))) {
               *_limit = -1;
               return 0;
        }

        ret = __hex2str(etime_hex, sizeof(etime_hex), etime, sizeof(etime));
        if (ret)
                GOTO(err_ret, ret);

        ret = AES_set_decrypt_key((uint8_t *)LICENSE_AES_KEY, 128, &key);
        if (ret < 0) {
                ret = EFAULT;
                GOTO(err_ret, ret);
        }

        AES_decrypt((uint8_t *)etime, (uint8_t *)epad, &key);

        memcpy(&limit, epad, sizeof(time_t));

        *_limit = LICENSE_DECRYPT(limit);

        return 0;
err_ret:
        return ret;
}
开发者ID:spawn3,项目名称:python-util,代码行数:53,代码来源:license.c

示例11: aes_decrypt_text

// cipterText: 암호문, plainText: 평문, key: 암호화에 사용할 키, keyLength: 키크기 128, 198, 256
unsigned char* aes_decrypt_text(unsigned char* cipherText, unsigned char* key, int keyLength)
{
	AES_KEY decKey;
	unsigned char* plainText = (unsigned char*)malloc(sizeof(cipherText));

	if (AES_set_decrypt_key(key, keyLength, &decKey) < 0)
		return NULL;

	AES_decrypt(cipherText, plainText, &decKey);

	return plainText;
}
开发者ID:twMobile,项目名称:securityComm,代码行数:13,代码来源:aesEncDec.cpp

示例12: edata_sign_free

int edata_sign_free(u8 *edata_buf, u8 *pgd_key)
{
	MAC_KEY mkey;
	AES_ctx aes;
	u8 sha1_hash[20], license_key[16];
	int flag, i;

	printf("re-sign EDATA ...\n");

	flag = *(u8*)(edata_buf+15);

	// get license_key
	if(flag&1){
		sceDrmBBMacInit(&mkey, 3);
		sceDrmBBMacUpdate(&mkey, edata_buf, 0x80);
		bbmac_getkey(&mkey, edata_buf+0x80, license_key);
		if(verbose) hex_dump("license key", license_key, 16);
	}

	// change to use free license
	*(u32*)(edata_buf+8) = 0x01000000;

	// build ecdsa
	ecdsa_set_curve(&ecdsa_app);
	ecdsa_set_priv(priv_key_edata);
	SHA1(edata_buf, 0x58, sha1_hash);
	ecdsa_sign(sha1_hash, edata_buf+0x58, edata_buf+0x6c, NULL);

	// build BBMAC
	if(flag&1){
		sceDrmBBMacInit(&mkey, 3);
		sceDrmBBMacUpdate(&mkey, edata_buf, 0x80);
		sceDrmBBMacFinal(&mkey, edata_buf+0x80, license_key);
		bbmac_build_final2(3, edata_buf+0x80);
	}

	// build PGD key
	sceNpDrmGetFixedKey(pgd_key, (char*)(edata_buf+16), 0x01000000);
	if(verbose) hex_dump("get_fixed_key", pgd_key, 16);

	if(flag&1){
		for(i=0; i<16; i++){
			pgd_key[i] ^= license_key[i];
		}
	}

	AES_set_key(&aes, edat_aeskey, 128);
	AES_decrypt(&aes, pgd_key, pgd_key);
	if(verbose) hex_dump("new PGD key", pgd_key, 16);

	return 0;
}
开发者ID:173210,项目名称:kirk_engine,代码行数:52,代码来源:edata.c

示例13: cbc_decrypt

void cbc_decrypt(char *encrypted, char *decrypted, size_t num_bytes, char *iv, char *key) {
    AES_KEY aes_key;
    AES_set_decrypt_key((unsigned char*)key, 128, &aes_key);
    char prev[16];
    char buf[16];
    memcpy(prev, iv, 16);
    for (size_t offset = 0; offset < num_bytes; offset += 16) {
    	memcpy(buf, encrypted + offset, 16);
        AES_decrypt((unsigned char*)encrypted + offset, (unsigned char*)decrypted + offset, &aes_key);
    	xor(decrypted + offset, prev, 16, decrypted + offset);
        memcpy(prev, buf, 16);
    }
}
开发者ID:hundt,项目名称:crypto-challenges,代码行数:13,代码来源:crypt.c

示例14: aes_decrypt

static int aes_decrypt(EdpPacket* pkg, int remain_pos){
    size_t in_len = 0;
    unsigned char* in = NULL;
    unsigned char* out = NULL;
    size_t offset = 0;
    size_t padding_len = 0;
    uint32 len_aft_dec = 0;
    uint8 tmp_buf[5] = {0};
    EdpPacket tmp_pkg;
    int diff = 0;
    int i = 0;

    in_len = pkg->_write_pos - pkg->_read_pos;
    in = pkg->_data + pkg->_read_pos;
    out = in;

    for (offset=0; (offset+AES_BLOCK_SIZE)<=in_len; offset+=AES_BLOCK_SIZE){
	AES_decrypt(in + offset, out + offset, &g_aes_decrypt_key);
    }

    padding_len = *(in + offset -1) - '0';
    if (padding_len > AES_BLOCK_SIZE){
	return -1;
    }

    /* 解密后的remainlen会变小,其占用空间可能变小
     * 利用一个临时的EdpPacket来测试加密后remainlen的长度是否发生改变
     * 若改变,则解密后的数据应该依次往前移,以消除多余空间
     */
    len_aft_dec = offset - padding_len;
    tmp_pkg._data = tmp_buf;
    tmp_pkg._write_pos = 1;
    tmp_pkg._read_pos = 0;
    WriteRemainlen(&tmp_pkg, len_aft_dec);

    diff = remain_pos - tmp_pkg._write_pos;
    if (diff > 0){
	i = 0;
	for (i=0; i<len_aft_dec; i++){
	    *(in + i - diff)  = *(in + i);
	}
    }
    
    pkg->_write_pos = 1;
    pkg->_read_pos = 0;
    WriteRemainlen(pkg, len_aft_dec);
    pkg->_read_pos = 1;
    pkg->_write_pos += len_aft_dec;

    return len_aft_dec;
}
开发者ID:EagleSmith,项目名称:edp_c,代码行数:51,代码来源:Openssl.c

示例15: plaintext

QByteArray
NvPairingManager::decrypt(QByteArray ciphertext, AES_KEY* key)
{
    QByteArray plaintext(ciphertext.size(), 0);

    for (int i = 0; i < plaintext.size(); i += 16)
    {
        AES_decrypt(reinterpret_cast<unsigned char*>(&ciphertext.data()[i]),
                    reinterpret_cast<unsigned char*>(&plaintext.data()[i]),
                    key);
    }

    return plaintext;
}
开发者ID:wwssr3,项目名称:moonlight-qt,代码行数:14,代码来源:nvpairingmanager.cpp


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