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


C++ EVP_aes_128_ecb函数代码示例

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


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

示例1: aes_ctr_init

static int
aes_ctr_init(archive_crypto_ctx *ctx, const uint8_t *key, size_t key_len)
{
	if ((ctx->ctx = EVP_CIPHER_CTX_new()) == NULL)
		return -1;

	switch (key_len) {
	case 16: ctx->type = EVP_aes_128_ecb(); break;
	case 24: ctx->type = EVP_aes_192_ecb(); break;
	case 32: ctx->type = EVP_aes_256_ecb(); break;
	default: ctx->type = NULL; return -1;
	}

	ctx->key_len = key_len;
	memcpy(ctx->key, key, key_len);
	memset(ctx->nonce, 0, sizeof(ctx->nonce));
	ctx->encr_pos = AES_BLOCK_SIZE;
#if OPENSSL_VERSION_NUMBER  >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
	if (!EVP_CIPHER_CTX_reset(ctx->ctx)) {
		EVP_CIPHER_CTX_free(ctx->ctx);
		ctx->ctx = NULL;
	}
#else
	EVP_CIPHER_CTX_init(ctx->ctx);
#endif
	return 0;
}
开发者ID:Bebere,项目名称:libarchive,代码行数:27,代码来源:archive_cryptor.c

示例2: EVP_aes_128_cbc

const EVP_CIPHER *OpensslAES::getEvpCipher() const
{
    if (m_type == TypeAes128 && m_mode == ModeCbc) {
        return EVP_aes_128_cbc();
    } else if (m_type == TypeAes128 && m_mode == ModeCfb) {
        return EVP_aes_128_cfb128();
    } else if (m_type == TypeAes128 && m_mode == ModeEcb) {
        return EVP_aes_128_ecb();
    } else if (m_type == TypeAes128 && m_mode == ModeOfb) {
        return EVP_aes_128_ofb();
    } else if (m_type == TypeAes192 && m_mode == ModeCbc) {
        return EVP_aes_192_cbc();
    } else if (m_type == TypeAes192 && m_mode == ModeCfb) {
        return EVP_aes_192_cfb128();
    } else if (m_type == TypeAes192 && m_mode == ModeEcb) {
        return EVP_aes_192_ecb();
    } else if (m_type == TypeAes192 && m_mode == ModeOfb) {
        return EVP_aes_192_ofb();
    } else if (m_type == TypeAes256 && m_mode == ModeCbc) {
        return EVP_aes_256_cbc();
    } else if (m_type == TypeAes256 && m_mode == ModeCfb) {
        return EVP_aes_256_cfb128();
    } else if (m_type == TypeAes256 && m_mode == ModeEcb) {
        return EVP_aes_256_ecb();
    } else if (m_type == TypeAes256 && m_mode == ModeOfb) {
        return EVP_aes_256_ofb();
    }

    return 0;
}
开发者ID:dushibaiyu,项目名称:QSocket5Tunnel,代码行数:30,代码来源:opensslaes.cpp

示例3: seafile_decrypt_init

int
seafile_decrypt_init (EVP_CIPHER_CTX *ctx,
                      int version,
                      const unsigned char *key,
                      const unsigned char *iv)
{
    int ret;

    /* Prepare CTX for decryption. */
    EVP_CIPHER_CTX_init (ctx);

    if (version >= 1)
        ret = EVP_DecryptInit_ex (ctx,
                                  EVP_aes_128_cbc(), /* cipher mode */
                                  NULL, /* engine, NULL for default */
                                  key,  /* derived key */
                                  iv);  /* initial vector */
    else
        ret = EVP_DecryptInit_ex (ctx,
                                  EVP_aes_128_ecb(), /* cipher mode */
                                  NULL, /* engine, NULL for default */
                                  key,  /* derived key */
                                  iv);  /* initial vector */

    if (ret == DEC_FAILURE)
        return -1;

    return 0;
}
开发者ID:2bj,项目名称:seafile,代码行数:29,代码来源:seafile-crypt.c

示例4: ossl_aes_ecb_init

static int
ossl_aes_ecb_init(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
{
	ossldata   *od = c->ptr;
	int			err;

	err = ossl_aes_init(c, key, klen, iv);
	if (err)
		return err;

	switch (od->klen)
	{
		case 128 / 8:
			od->evp_ciph = EVP_aes_128_ecb();
			break;
		case 192 / 8:
			od->evp_ciph = EVP_aes_192_ecb();
			break;
		case 256 / 8:
			od->evp_ciph = EVP_aes_256_ecb();
			break;
		default:
			/* shouldn't happen */
			err = PXE_CIPHER_INIT;
			break;
	}

	return err;
}
开发者ID:cconvey,项目名称:postgres,代码行数:29,代码来源:openssl.c

示例5: MissingParameterException

/** Decrypt.
 * Do the decryption.
 * @return size of the plain text message.
 */
size_t
WorldInfoMessageDecryptor::decrypt()
{
  if ( (plain_buffer == NULL) || (plain_buffer_length == 0) ||
       (crypt_buffer == NULL) || (crypt_buffer_length == 0) ) {
    throw MissingParameterException("Buffer(s) not set for decryption");
  }

#ifdef HAVE_LIBCRYPTO
  EVP_CIPHER_CTX ctx;
  if ( ! EVP_DecryptInit(&ctx, EVP_aes_128_ecb(), key, iv) ) {
    throw MessageDecryptionException("Could not initialize cipher context");
  }

  int outl = plain_buffer_length;
  if ( ! EVP_DecryptUpdate(&ctx,
			   (unsigned char *)plain_buffer, &outl,
			   (unsigned char *)crypt_buffer, crypt_buffer_length) ) {
    throw MessageDecryptionException("DecryptUpdate failed");
  }

  int plen = 0;
  if ( ! EVP_DecryptFinal(&ctx, (unsigned char *)plain_buffer + outl, &plen) ) {
    throw MessageDecryptionException("DecryptFinal failed");
  }
  outl += plen;

  return outl;
#else
  // Plain-text copy-through for debugging.
  memcpy(plain_buffer, crypt_buffer, crypt_buffer_length);
  return crypt_buffer_length;
#endif
}
开发者ID:fuxiang90,项目名称:fawkes,代码行数:38,代码来源:decrypt.cpp

示例6: problem07

std::string problem07() {
    std::ifstream instream;
    instream.open(rootdir + "res/p7.txt", std::ios::in);
    if (!instream.is_open()) {
        std::cerr << "Can't open p7.txt\n";
        return std::string("p07 failed.\n");
    }
    std::string in{};
    std::string line;
    while(std::getline(instream, line)) {
        in += line;
    }
    BinaryBlob b7 = BinaryBlob(in, 64);
    int num_bytes = b7.size();
    int act_num_bytes = 0, tot_bytes = 0;
    unsigned char key[] = "YELLOW SUBMARINE";
    EVP_CIPHER_CTX* my_cipher_ctx = EVP_CIPHER_CTX_new();
    EVP_DecryptInit_ex(my_cipher_ctx, EVP_aes_128_ecb(), NULL, key, NULL);
    unsigned char* out = (unsigned char *) malloc(num_bytes * 2 + EVP_CIPHER_CTX_block_size(my_cipher_ctx));
    if (!out)
        return  "p7 - OOM\n";
    EVP_DecryptUpdate(my_cipher_ctx, out, &act_num_bytes, b7.getRawBuf(), num_bytes);
    tot_bytes += act_num_bytes;
    EVP_DecryptFinal_ex(my_cipher_ctx, out + act_num_bytes, &act_num_bytes);
    tot_bytes += act_num_bytes;
    EVP_CIPHER_CTX_free(my_cipher_ctx);
    BinaryBlob s7 = BinaryBlob(out, tot_bytes);
    return s7.ascii();
}
开发者ID:dcashman,项目名称:cryptopals,代码行数:29,代码来源:matasano_set01.cpp

示例7: XCBC_Init

int
XCBC_Init(XCBC_CTX *xctx,
	  const uint8_t const *k)
{
	int bl, outl;
	EVP_CIPHER_CTX *ctx;
	uint8_t k1[XCBC_MAX_BLOCK_LENGTH];

	ctx = xctx->ctx;

	EVP_CIPHER_CTX_init(ctx);
	OPENSSL_try(EVP_CipherInit_ex(ctx, EVP_aes_128_ecb(), NULL, k, NULL, 1),
		    "cipher init error", return0);
	bl = EVP_CIPHER_CTX_block_size((const EVP_CIPHER_CTX *)ctx);
	OPENSSL_try(EVP_CipherUpdate(ctx,       k1, &outl, ks1, bl),
		    "cipher update error (k1)", return0);
	OPENSSL_try(EVP_CipherUpdate(ctx, xctx->k2, &outl, ks2, bl),
		    "cipher update error (k2)", return0);
	OPENSSL_try(EVP_CipherUpdate(ctx, xctx->k3, &outl, ks3, bl),
		    "cipher update error (k3)", return0);

	OPENSSL_try(EVP_CipherInit_ex(ctx, NULL, NULL, k1, NULL, -1),
		    "cipher reset error", return0);
	memset(xctx->e, 0, bl);
	xctx->size = 0;

	return 1;

return0:
	return 0;
}
开发者ID:grivet,项目名称:XCBC,代码行数:31,代码来源:xcbc.c

示例8: EVP_CIPHER_CTX_new

ndn_Error
ndn_AesAlgorithm_decrypt128Ecb
  (const uint8_t *key, size_t keyLength, const uint8_t *encryptedData,
   size_t encryptedDataLength, uint8_t *plainData, size_t *plainDataLength)
{
  EVP_CIPHER_CTX *ctx;
  int outLength1, outLength2;

  if (keyLength != ndn_AES_128_BLOCK_SIZE)
    return NDN_ERROR_Incorrect_key_size;

  ctx = EVP_CIPHER_CTX_new();
  if (!ctx)
    return NDN_ERROR_Error_in_decrypt_operation;

  EVP_DecryptInit(ctx, EVP_aes_128_ecb(), (const unsigned char*)key, 0);

  EVP_DecryptUpdate
    (ctx, (unsigned char*)plainData, &outLength1,
     (const unsigned char*)encryptedData, encryptedDataLength);
  EVP_DecryptFinal
    (ctx, (unsigned char*)plainData + outLength1, &outLength2);

  EVP_CIPHER_CTX_free(ctx);
  *plainDataLength = outLength1 + outLength2;

  return NDN_ERROR_success;
}
开发者ID:yoursunny,项目名称:esp8266ndn,代码行数:28,代码来源:aes-algorithm_c.c

示例9: aes_128_encrypt_block

static inline int aes_128_encrypt_block(EVP_CIPHER_CTX *evp_ctx,
					uint8_t const key[16], uint8_t const in[16], uint8_t out[16])
{
	size_t len;

	if (unlikely(EVP_EncryptInit_ex(evp_ctx, EVP_aes_128_ecb(), NULL, key, NULL) != 1)) {
		tls_strerror_printf("Failed initialising AES-128-ECB context");
		return -1;
	}

	/*
	 *	By default OpenSSL will try and pad out a 16 byte
	 *	plaintext to 32 bytes so that it's detectable that
	 *	there was padding.
	 *
	 *	In this case we know the length of the plaintext
	 *	we're trying to recover, so we explicitly tell
	 *	OpenSSL not to pad here, and not to expected padding
	 *	when decrypting.
	 */
	EVP_CIPHER_CTX_set_padding(evp_ctx, 0);
	if (unlikely(EVP_EncryptUpdate(evp_ctx, out, (int *)&len, in, 16) != 1) ||
	    unlikely(EVP_EncryptFinal_ex(evp_ctx, out + len, (int *)&len) != 1)) {
		tls_strerror_printf("Failed encrypting data");
		return -1;
	}

	return 0;
}
开发者ID:mcnewton,项目名称:freeradius-server,代码行数:29,代码来源:milenage.c

示例10: aesEncrypt

static int aesEncrypt(char* input, int inlen, char* output, int* outlen) {
    int c_len; //length of ciphertext
    int f_len; //rest length of padded ciphertext
    EVP_CIPHER_CTX ctx;

    if (input == NULL || inlen <= 0 || output == NULL || *outlen <= 0) {
        return -1;
    }

    EVP_CIPHER_CTX_init(&ctx);

    if (EVP_EncryptInit_ex(&ctx, EVP_aes_128_ecb(), NULL, key, NULL) != 1) {
        return -2;
    }

    if (EVP_EncryptUpdate(&ctx, (unsigned char*)output, &c_len, (const unsigned char*)input,
                          inlen) != 1) {
        return -3;
    }

    if (EVP_EncryptFinal_ex(&ctx, (unsigned char*)(output + c_len), &f_len) != 1) {
        return -4;
    }

    EVP_CIPHER_CTX_cleanup(&ctx);

    *outlen = c_len + f_len;
    return 0;
}
开发者ID:cumirror,项目名称:epoll_example,代码行数:29,代码来源:coding.c

示例11: mp4_aes_ctr_init

vod_status_t
mp4_aes_ctr_init(
	mp4_aes_ctr_state_t* state,
	request_context_t* request_context, 
	u_char* key)
{
	vod_pool_cleanup_t *cln;

	state->request_context = request_context;

	cln = vod_pool_cleanup_add(request_context->pool, 0);
	if (cln == NULL)
	{
		vod_log_debug0(VOD_LOG_DEBUG_LEVEL, request_context->log, 0,
			"mp4_aes_ctr_init: vod_pool_cleanup_add failed");
		return VOD_ALLOC_FAILED;
	}

	cln->handler = (vod_pool_cleanup_pt)mp4_aes_ctr_cleanup;
	cln->data = state;

	EVP_CIPHER_CTX_init(&state->cipher);

	if (1 != EVP_EncryptInit_ex(&state->cipher, EVP_aes_128_ecb(), NULL, key, NULL))
	{
		vod_log_error(VOD_LOG_ERR, request_context->log, 0,
			"mp4_aes_ctr_init: EVP_EncryptInit_ex failed");
		return VOD_ALLOC_FAILED;
	}

	return VOD_OK;
}
开发者ID:Boburjon,项目名称:nginx-vod-module,代码行数:32,代码来源:mp4_aes_ctr.c

示例12: aes_f8_session_key_init

static int aes_f8_session_key_init(struct crypto_context *c) {
	unsigned char m[16];
	int i;
	int k_e_len, k_s_len; /* n_e, n_s */
	unsigned char *key;

	aes_cm_session_key_init(c);

	k_e_len = c->crypto_suite->session_key_len;
	k_s_len = c->crypto_suite->session_salt_len;
	key = (unsigned char *) c->session_key;

	/* m = k_s || 0x555..5 */
	memcpy(m, c->session_salt, k_s_len);
	for (i = k_s_len; i < k_e_len; i++)
		m[i] = 0x55;
	/* IV' = E(k_e XOR m, IV) */
	for (i = 0; i < k_e_len; i++)
		m[i] ^= key[i];

	c->session_key_ctx[1] = g_slice_alloc(sizeof(EVP_CIPHER_CTX));
	EVP_CIPHER_CTX_init(c->session_key_ctx[1]);
	EVP_EncryptInit_ex(c->session_key_ctx[1], EVP_aes_128_ecb(), NULL, m, NULL);

	return 0;
}
开发者ID:SibghatullahSheikh,项目名称:mediaproxy-ng,代码行数:26,代码来源:crypto.c

示例13: aes_set_key

/** Set the key of <b>cipher</b> to <b>key</b>, which is
 * <b>key_bits</b> bits long (must be 128, 192, or 256).  Also resets
 * the counter to 0.
 */
static void
aes_set_key(aes_cnt_cipher_t *cipher, const char *key, int key_bits)
{
  if (should_use_EVP) {
    const EVP_CIPHER *c = 0;
    switch (key_bits) {
      case 128: c = EVP_aes_128_ecb(); break;
      case 192: c = EVP_aes_192_ecb(); break;
      case 256: c = EVP_aes_256_ecb(); break;
      default: tor_assert(0);
    }
    EVP_EncryptInit(&cipher->key.evp, c, (const unsigned char*)key, NULL);
    cipher->using_evp = 1;
  } else {
    AES_set_encrypt_key((const unsigned char *)key, key_bits,&cipher->key.aes);
    cipher->using_evp = 0;
  }

#ifdef USING_COUNTER_VARS
  cipher->counter0 = 0;
  cipher->counter1 = 0;
  cipher->counter2 = 0;
  cipher->counter3 = 0;
#endif

  memset(cipher->ctr_buf.buf, 0, sizeof(cipher->ctr_buf.buf));

  cipher->pos = 0;

  memset(cipher->buf, 0, sizeof(cipher->buf));
}
开发者ID:themiron,项目名称:asuswrt-merlin,代码行数:35,代码来源:aes.c

示例14: seafile_derive_key

int
seafile_derive_key (const char *data_in, int in_len, int version,
                    unsigned char *key, unsigned char *iv)
{
    if (version == 2) {
        PKCS5_PBKDF2_HMAC (data_in, in_len,
                           salt, sizeof(salt),
                           KEYGEN_ITERATION2,
                           EVP_sha256(),
                           32, key);
        PKCS5_PBKDF2_HMAC ((char *)key, 32,
                           salt, sizeof(salt),
                           10,
                           EVP_sha256(),
                           16, iv);
        return 0;
    } else if (version == 1)
        return EVP_BytesToKey (EVP_aes_128_cbc(), /* cipher mode */
                               EVP_sha1(),        /* message digest */
                               salt,              /* salt */
                               (unsigned char*)data_in,
                               in_len,
                               KEYGEN_ITERATION,   /* iteration times */
                               key, /* the derived key */
                               iv); /* IV, initial vector */
    else
        return EVP_BytesToKey (EVP_aes_128_ecb(), /* cipher mode */
                               EVP_sha1(),        /* message digest */
                               NULL,              /* salt */
                               (unsigned char*)data_in,
                               in_len,
                               3,   /* iteration times */
                               key, /* the derived key */
                               iv); /* IV, initial vector */
}
开发者ID:Danath,项目名称:seafile,代码行数:35,代码来源:seafile-crypt.c

示例15: get_cipher_type

const EVP_CIPHER* get_cipher_type(const enum cipher cipher, const enum cipher_mode mode) {

    switch (mode) {
        case MODE_ECB:

            switch (cipher) {
                case CIPHER_DES:
                    return EVP_des_ecb();
                case CIPHER_AES_128:
                    return EVP_aes_128_ecb();
                case CIPHER_AES_192:
                    return EVP_aes_192_ecb();
                case CIPHER_AES_256:
                    return EVP_aes_256_ecb();
            }

        case MODE_CBC:

            switch (cipher) {
                case CIPHER_DES:
                    return EVP_des_cbc();
                case CIPHER_AES_128:
                    return EVP_aes_128_cbc();
                case CIPHER_AES_192:
                    return EVP_aes_192_cbc();
                case CIPHER_AES_256:
                    return EVP_aes_256_cbc();
            }

        case MODE_OFB:

            switch (cipher) {
                case CIPHER_DES:
                    return EVP_des_ofb();
                case CIPHER_AES_128:
                    return EVP_aes_128_ofb();
                case CIPHER_AES_192:
                    return EVP_aes_192_ofb();
                case CIPHER_AES_256:
                    return EVP_aes_256_ofb();
            }

        case MODE_CFB:

            switch (cipher) {
                case CIPHER_DES:
                    return EVP_des_cfb();
                case CIPHER_AES_128:
                    return EVP_aes_128_cfb();
                case CIPHER_AES_192:
                    return EVP_aes_192_cfb();
                case CIPHER_AES_256:
                    return EVP_aes_256_cfb();
            }
    }

    abort();
}
开发者ID:acrespo,项目名称:cripto-2013-1c,代码行数:58,代码来源:crypt.c


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