• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ AES_decrypt函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: encrypt_data

void encrypt_data(FILE* input_file, FILE* output_file)
{
	unsigned char inbuf[80];
	unsigned char outbuf[80];
	unsigned char decbuf[80];
	int inlen, outlen;

	AES_KEY enc_key;
	AES_KEY dec_key;
	AES_set_encrypt_key(key, 128, &enc_key);

	//while(1) {
		int i;
		inlen = 80;
		outlen = 80;
//		inlen = fread(inbuf, 1, 80, input_file);
		for (i=0; i<inlen; i++) {
			inbuf[i]=0;
		}
		printf("input data is \n");
		for (i = 0; i < inlen; i++) {
			printf("%c ", inbuf[i]);
		}
		printf("\n");

		AES_encrypt(inbuf, outbuf, &enc_key);  

		printf("encrypted data is \n");
		for (i = 0; i < inlen; i++) {
			printf("%X ", outbuf[i]);
		}
		printf("\n");
		
		AES_set_decrypt_key(key, 128, &dec_key);
		AES_decrypt(outbuf, decbuf, &dec_key);  

		printf("decrypted data is \n");
		for (i = 0; i < inlen; i++) {
			printf("%c ", decbuf[i]);
		}
		printf("\n");

		outlen = fwrite(outbuf, 1, inlen, output_file);

//		if (outlen < AES_BLOCK_SIZE)
//		{
//			break;
//		}
	//}
}
开发者ID:jagleeso,项目名称:jiawen-opencl,代码行数:50,代码来源:cpu-aes.c


示例17: qcrypto_cipher_aes_ecb_decrypt

static void qcrypto_cipher_aes_ecb_decrypt(AES_KEY *key,
                                           const void *in,
                                           void *out,
                                           size_t len)
{
    const uint8_t *inptr = in;
    uint8_t *outptr = out;
    while (len) {
        if (len > AES_BLOCK_SIZE) {
            AES_decrypt(inptr, outptr, key);
            inptr += AES_BLOCK_SIZE;
            outptr += AES_BLOCK_SIZE;
            len -= AES_BLOCK_SIZE;
        } else {
            uint8_t tmp1[AES_BLOCK_SIZE], tmp2[AES_BLOCK_SIZE];
            memcpy(tmp1, inptr, len);
            /* Fill with 0 to avoid valgrind uninitialized reads */
            memset(tmp1 + len, 0, sizeof(tmp1) - len);
            AES_decrypt(tmp1, tmp2, key);
            memcpy(outptr, tmp2, len);
            len = 0;
        }
    }
}
开发者ID:01org,项目名称:qemu-lite,代码行数:24,代码来源:cipher-builtin.c


示例18: decryptImage

void decryptImage(unsigned char* srcaddr, unsigned int len, unsigned char* dstaddr) {
	unsigned int remaining = len;
	unsigned int decrypted = 0;
	while (remaining >= AES_BLOCK_SIZE) {
		AES_decrypt(srcaddr, dstaddr, &_gdKeyImage);
		srcaddr += AES_BLOCK_SIZE;
		dstaddr += AES_BLOCK_SIZE;
		remaining -= AES_BLOCK_SIZE;
		decrypted++;
	}
	if (remaining != 0) {
		decrypted = decrypted * AES_BLOCK_SIZE;
		memcpy(dstaddr, srcaddr, remaining);
	}
}
开发者ID:Acidburn0zzz,项目名称:epk2extract,代码行数:15,代码来源:epk2.c


示例19: decrypt_block

void decrypt_block(struct poet_ctx *ctx, const uint8_t ciphertext[16],
		   uint8_t plaintext[16])
{
  block tmp;
  BOTTOM_HASH;
  xor_block(ctx->y, ciphertext,ctx->y);

  AES_decrypt(ctx->y, tmp, &(ctx->aes_dec));

  TOP_HASH;
  xor_block(plaintext, tmp,ctx->x);

  memcpy(ctx->x, tmp, BLOCKLEN);
  ctx->mlen+=BLOCKLEN_BITS;
}
开发者ID:JacobBarthelmeh,项目名称:supercop,代码行数:15,代码来源:poet.c


示例20: aesBlock

/* Encrypt or decrypt one block with AES and the given key */
static void aesBlock(unsigned char out[16], const unsigned char key[],
                     int keyBits, const unsigned char in[16], int dir)
{
  extern void exit(int status);
  int retCode;
  AES_KEY aesKey;

  if (dir==AES_ENCRYPT)
    retCode = AES_set_encrypt_key(key, keyBits, &aesKey);
  else
    retCode = AES_set_decrypt_key(key, keyBits, &aesKey);
  if (retCode!=0) exit(retCode);       /* Not very gracefull, but still... */

  if (dir==AES_ENCRYPT) AES_encrypt(in, out, &aesKey);
  else                  AES_decrypt(in, out, &aesKey);
}
开发者ID:rfjakob,项目名称:crypto1619,代码行数:17,代码来源:eme2-ref.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ AES_set_decrypt_key函数代码示例发布时间:2022-05-30
下一篇:
C++ AES_cbc_encrypt函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap