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


C++ EVP_CIPHER_block_size函数代码示例

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


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

示例1: main

int main(int argc, char **argv)
{
	int i;
	char *names[] = {
		"sms4-ecb",
		"sms4-cbc",
		"sms4-cfb",
		"sms4-ofb",
		"sms4-ctr",
	};
	const EVP_CIPHER *cipher;
	
	OpenSSL_add_all_ciphers();

	printf("%s new ciphers:\n\n", OPENSSL_VERSION_TEXT);

	for (i = 0; i < sizeof(names)/sizeof(names[i]); i++) {
		if (!(cipher = EVP_get_cipherbyname(names[i]))) {
			fprintf(stderr, "cipher \"%s\" is not supported\n", names[i]);
			continue;
		}

		printf("  cipher nid : %d\n", EVP_CIPHER_nid(cipher));
		printf(" cipher name : %s\n", EVP_CIPHER_name(cipher));
		printf("  block size : %d\n", EVP_CIPHER_block_size(cipher));
		printf("  key length : %d\n", EVP_CIPHER_key_length(cipher));
		printf("   iv length : %d\n", EVP_CIPHER_iv_length(cipher));
		printf("       flags : 0x%016lx\n", EVP_CIPHER_flags(cipher));
		printf("\n");
	}

	return 0;
}
开发者ID:kenchowcn,项目名称:GmSSL,代码行数:33,代码来源:listciphers.c

示例2: wi_cipher_decrypt_bytes

wi_boolean_t wi_cipher_decrypt_bytes(wi_cipher_t *cipher, const void *encrypted_buffer, wi_uinteger_t encrypted_length, void **out_buffer, wi_uinteger_t *out_length) {
	void		*decrypted_buffer;
	int			decrypted_length, padded_length;
	
	decrypted_buffer = wi_malloc(encrypted_length + EVP_CIPHER_block_size(cipher->cipher));
	
	if(EVP_DecryptUpdate(&cipher->decrypt_ctx, decrypted_buffer, &decrypted_length, encrypted_buffer, encrypted_length) != 1) {
		wi_error_set_openssl_error();
		
		wi_free(decrypted_buffer);
		
		return false;
	}
	
	if(EVP_DecryptFinal_ex(&cipher->decrypt_ctx, decrypted_buffer + decrypted_length, &padded_length) != 1) {
		wi_error_set_openssl_error();
		
		wi_free(decrypted_buffer);
		
		return false;
	}
	
	if(EVP_DecryptInit_ex(&cipher->decrypt_ctx, NULL, NULL, NULL, NULL) != 1) {
		wi_error_set_openssl_error();
		
		wi_free(decrypted_buffer);
		
		return false;
	}
	
	*out_buffer = decrypted_buffer;
	*out_length = decrypted_length + padded_length;
	
	return true;
}
开发者ID:ProfDrLuigi,项目名称:zanka,代码行数:35,代码来源:wi-crypto.c

示例3: pbaes256_decrypt_alloc

pubnub_bymebl_t pbaes256_decrypt_alloc(pubnub_bymebl_t data, uint8_t const* key, uint8_t const* iv)
{
    int decrypt_result;
    EVP_CIPHER_CTX *aes256;
    pubnub_bymebl_t result;

    result.size = data.size + EVP_CIPHER_block_size(EVP_aes_256_cbc()) + 1;
    result.ptr = (uint8_t*)malloc(result.size);
    if (NULL == result.ptr) {
        return result;
    }

    aes256 = EVP_CIPHER_CTX_new();
    if (NULL == aes256) {
        PUBNUB_LOG_ERROR("Failed to allocate AES-256 decryption context\n");
        free(result.ptr);
        result.ptr = NULL;
        return result;;
    }

    decrypt_result = do_decrypt(aes256, data, key, iv, &result);

    EVP_CIPHER_CTX_free(aes256);

    if (decrypt_result != 0) {
        PUBNUB_LOG_ERROR("Failed AES-256 decryption\n");
        free(result.ptr);
        result.ptr = NULL;
    }

    return result;
}
开发者ID:sveljko,项目名称:c-core,代码行数:32,代码来源:pbaes256.c

示例4: pbaes256_encrypt_alloc

pubnub_bymebl_t pbaes256_encrypt_alloc(pubnub_bymebl_t msg, uint8_t const* key, uint8_t const* iv)
{
    int encrypt_result;
    pubnub_bymebl_t result = { NULL, 0 };
    EVP_CIPHER_CTX* aes256 = EVP_CIPHER_CTX_new();

    if (NULL == aes256) {
        PUBNUB_LOG_ERROR("Failed to allocate AES-256 encryption context\n");
        return result;
    }

    result.ptr = (uint8_t*)malloc(msg.size + EVP_CIPHER_block_size(EVP_aes_256_cbc()));
    if (NULL == result.ptr) {
        EVP_CIPHER_CTX_free(aes256);
        PUBNUB_LOG_ERROR("Failed to allocate memory for AES-256 encryption\n");
        return result;
    }
    
    encrypt_result = do_encrypt(aes256, msg, key, iv, &result);
    if (-1 == encrypt_result) {
        free(result.ptr);
        result.ptr = NULL;
    }
    EVP_CIPHER_CTX_free(aes256);

    return result;
}
开发者ID:sveljko,项目名称:c-core,代码行数:27,代码来源:pbaes256.c

示例5: RTDECL

RTDECL(uint32_t) RTCrCipherGetBlockSize(RTCRCIPHER hCipher)
{
    RTCRCIPHERINT *pThis = hCipher;
    AssertPtrReturn(pThis, 0);
    AssertReturn(pThis->u32Magic == RTCRCIPHERINT_MAGIC, 0);

    return EVP_CIPHER_block_size(pThis->pCipher);
}
开发者ID:mdaniel,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:8,代码来源:cipher-openssl.cpp

示例6: pubnub_decrypt

static struct json_object *
pubnub_decrypt(const char *cipher_key, const char *b64_str)
{
	int b64_len = strlen(b64_str);
	unsigned char iv[] = "0123456789012345";

	/* Pre-process (hash) encryption key */

	unsigned char cipher_hash[33];
	pubnub_sha256_cipher_key(cipher_key, cipher_hash);

	/* Convert base64 encrypted text to raw data. */

	BIO *b64f = BIO_new(BIO_f_base64());
	BIO_set_flags(b64f, BIO_FLAGS_BASE64_NO_NL);
	BIO *bmem = BIO_new_mem_buf((unsigned char *) b64_str, b64_len);
	BIO *b64 = BIO_push(b64f, bmem);
	/* b64_len is fine upper bound for raw data length... */
	unsigned char *cipher_data = (unsigned char*)malloc(b64_len);
	int cipher_len = BIO_read(b64, cipher_data, b64_len);
	BIO_free_all(b64);

	/* Decrypt the message */

	EVP_CIPHER_CTX aes256;
	EVP_CIPHER_CTX_init(&aes256);
	if (!EVP_DecryptInit_ex(&aes256, EVP_aes_256_cbc(), NULL, cipher_hash, iv)) {
		DBGMSG("DecryptInit error\n");
		return NULL;
	}

	char *message_str = (char*)malloc(cipher_len + EVP_CIPHER_block_size(EVP_aes_256_cbc()) + 1);
	int message_len = 0;
	if (!EVP_DecryptUpdate(&aes256, (unsigned char *) message_str, &message_len, cipher_data, cipher_len)) {
		DBGMSG("DecryptUpdate error\n");
		return NULL;
	}
	int message_flen;
	if (!EVP_DecryptFinal_ex(&aes256, (unsigned char *) message_str + message_len, &message_flen)) {
		DBGMSG("DecryptFinal error\n");
		return NULL;
	}
	message_len += message_flen;

	EVP_CIPHER_CTX_cleanup(&aes256);
	free(cipher_data);

	/* Conjure up JSON object */

	message_str[message_len] = 0;
	DBGMSG("dec inp: <%s>\n", message_str);
	struct json_object *message = json_tokener_parse(message_str);
	free(message_str);
	return message;
}
开发者ID:Roenke,项目名称:unix_labs,代码行数:55,代码来源:file.c

示例7: OpenSSL_add_all_ciphers

bool Crypto_t::symmetricCipher(const std::vector<unsigned char>& in_buffer, int nid, const std::string& key, const std::string& iv, bool encode, std::vector<unsigned char>& buffer)
{
	// load all cipher modules
	OpenSSL_add_all_ciphers();

	// Select the specific cipher module
	const EVP_CIPHER* cipher = EVP_get_cipherbynid(nid);
	if (!cipher) return false;

	// Each cipher has its own taste for the key and IV. So we need to check if the input key and IV is appropriate
	// for the specific cipher module
	if (key.size() < static_cast<size_t>(EVP_CIPHER_key_length(cipher)) || iv.size() < static_cast<size_t>(EVP_CIPHER_iv_length(cipher)))
	{
		return false;
	}

	EVP_CIPHER_CTX ctx;
	EVP_CIPHER_CTX_init(&ctx);
	EVP_CipherInit_ex(&ctx, cipher, NULL, (const unsigned char*)key.c_str(), (const unsigned char*)iv.c_str(), encode);
	size_t block_size = EVP_CIPHER_block_size(cipher);
	unsigned char* encrypt_buffer = (unsigned char*) malloc(block_size + in_buffer.size());

	// Read the raw buffer and convert to encrypt one. And then collect to the output buffer

	int out_count = 0;
	buffer.clear();
	bool fail = false;

	while (true)
	{
		if (!EVP_CipherUpdate(&ctx, encrypt_buffer, &out_count, &in_buffer[0], in_buffer.size()))
		{
			fail = true;
			break;
		}
		for (int i = 0; i < out_count; i++)
			buffer.push_back(encrypt_buffer[i]);

		// handling the last block
		unsigned char* block = encrypt_buffer + out_count;
		if (!EVP_CipherFinal_ex(&ctx, block, &out_count))
		{
			fail = true;
			break;
		}
		for (int i = 0; i < out_count; i++)
			buffer.push_back(block[i]);
		break;
	}

	// free resource
	free(encrypt_buffer);
	EVP_CIPHER_CTX_cleanup(&ctx);
	return (fail == true) ? (false) : (true);
}
开发者ID:zillians,项目名称:supercell_common,代码行数:55,代码来源:Crypto.cpp

示例8: cipher_kt_block_size

int
cipher_kt_block_size(const EVP_CIPHER *cipher)
{
    /*
     * OpenSSL reports OFB/CFB/GCM cipher block sizes as '1 byte'.  To work
     * around that, try to replace the mode with 'CBC' and return the block size
     * reported for that cipher, if possible.  If that doesn't work, just return
     * the value reported by OpenSSL.
     */
    char *name = NULL;
    char *mode_str = NULL;
    const char *orig_name = NULL;
    const EVP_CIPHER *cbc_cipher = NULL;

    int block_size = EVP_CIPHER_block_size(cipher);

    orig_name = cipher_kt_name(cipher);
    if (!orig_name)
    {
        goto cleanup;
    }

    name = string_alloc(translate_cipher_name_to_openvpn(orig_name), NULL);
    mode_str = strrchr(name, '-');
    if (!mode_str || strlen(mode_str) < 4)
    {
        goto cleanup;
    }

    strcpy(mode_str, "-CBC");

    cbc_cipher = EVP_get_cipherbyname(translate_cipher_name_from_openvpn(name));
    if (cbc_cipher)
    {
        block_size = EVP_CIPHER_block_size(cbc_cipher);
    }

cleanup:
    free(name);
    return block_size;
}
开发者ID:lstipakov,项目名称:openvpn,代码行数:41,代码来源:crypto_openssl.c

示例9: sl_decrypt

static void sl_decrypt (void){
  /* input types */
  char *ctype;
  unsigned char *outbuf, *iiv, *ikey, *idata;
  SLang_BString_Type *iv, *key, *data;
  /* internal types */
  EVP_CIPHER_CTX ctx;
  const EVP_CIPHER *cipher;
  int outlen, tmplen, dlen, i;
  /* output types */
  SLang_BString_Type *output;

  if (SLang_Num_Function_Args != 4 ||
      SLang_pop_slstring(&ctype) == -1 ){
    return; }

  cipher = EVP_get_cipherbyname(ctype);
  if (!cipher){
    SLang_verror(SL_UNDEFINED_NAME,"could not find cipher %s",ctype);
    return;
  }
  
  if (SLang_pop_bstring(&iv) == -1 ||
      SLang_pop_bstring(&key) == -1 ||
      SLang_pop_bstring(&data) == -1 ){
    return; }

  iiv = SLbstring_get_pointer (iv,&i);
  ikey = SLbstring_get_pointer (key,&i);
  idata = SLbstring_get_pointer (data,&dlen);

  outbuf = (char*)malloc(dlen+EVP_CIPHER_block_size(cipher));

  EVP_CIPHER_CTX_init(&ctx);
  EVP_DecryptInit_ex(&ctx, cipher, NULL, ikey, iiv);
  
  if (!EVP_DecryptUpdate(&ctx, outbuf, &outlen, idata, dlen)){
    return; /*emit an error here*/
  }
  if (!EVP_DecryptFinal(&ctx, outbuf + outlen, &tmplen)){
    return; /*emit an error here*/
  }
  outlen+=tmplen;

  output = SLbstring_create (outbuf, outlen);
  
  SLang_push_bstring(output);
  SLbstring_free(output);
  SLbstring_free(data);
  SLbstring_free(key);
  SLbstring_free(iv);
  free(outbuf);
}
开发者ID:amitschang,项目名称:slcrypto,代码行数:53,代码来源:crypto-module.c

示例10: LUA_FUNCTION

/* evp_cipher method */
static LUA_FUNCTION(openssl_cipher_info)
{
  EVP_CIPHER *cipher = CHECK_OBJECT(1, EVP_CIPHER, "openssl.evp_cipher");
  lua_newtable(L);
  AUXILIAR_SET(L, -1, "name", EVP_CIPHER_name(cipher), string);
  AUXILIAR_SET(L, -1, "block_size", EVP_CIPHER_block_size(cipher), integer);
  AUXILIAR_SET(L, -1, "key_length", EVP_CIPHER_key_length(cipher), integer);
  AUXILIAR_SET(L, -1, "iv_length", EVP_CIPHER_iv_length(cipher), integer);
  AUXILIAR_SET(L, -1, "flags", EVP_CIPHER_flags(cipher), integer);
  AUXILIAR_SET(L, -1, "mode", EVP_CIPHER_mode(cipher), integer);
  return 1;
}
开发者ID:world100,项目名称:11111,代码行数:13,代码来源:cipher.c

示例11: ship_encrypt

unsigned char*
ship_encrypt(const char *algo, unsigned char *key, unsigned char *iv, unsigned char *text, int *clen)
{
	unsigned char *cipher = NULL;
	unsigned char *c = NULL;
	unsigned char out[1024 + EVP_MAX_BLOCK_LENGTH];
	unsigned char in[1024];
	int olen = 0, ilen = 0, bsize = 0, i = 0, tlen = 0, csize = 0;
	EVP_CIPHER_CTX ctx;
	const EVP_CIPHER *ci;

	EVP_CIPHER_CTX_init (&ctx);
	ci = EVP_get_cipherbyname(algo);
	if (!ci) {
		LOG_ERROR("unknown cipher algorithm %s\n", algo);
		goto err;
	}
	
	ASSERT_TRUE(bsize = EVP_CIPHER_block_size(ci), err);
	tlen = strlen((char*)text);
	csize = ((tlen/bsize + 1) * bsize) + 1;
	ASSERT_TRUE(cipher = mallocz(csize * sizeof(unsigned char)), err);
	ASSERT_TRUE(EVP_EncryptInit_ex(&ctx, ci, NULL, key, iv), err);
	
	c = cipher;
	*clen = 0;
	while (i < tlen) {
		
		/* get part of text */
		ilen = (i+1024<tlen)?1024:tlen-i;
		memcpy (in, text, ilen);
		text += ilen;
		i += ilen;
		
		/* copy encrypt-part */
		ASSERT_TRUE(EVP_EncryptUpdate (&ctx, out, &olen, in, ilen), err);
		memcpy (c, out, olen);
		c += olen;
		
		/* increment cipher len */
		*clen += olen;
	}

	ASSERT_TRUE(EVP_EncryptFinal_ex(&ctx, out, &olen), err);
	memcpy (c, out, olen);
	*clen += olen;
	
	EVP_CIPHER_CTX_cleanup(&ctx);
	return cipher;
 err: 
	freez(cipher);
	return NULL;
}
开发者ID:sksushilkumar,项目名称:p2pship,代码行数:53,代码来源:ship_crypto.c

示例12: get_EVP_CIPHER_once_cb

static void
get_EVP_CIPHER_once_cb(void *d)
{
    struct once_init_cipher_ctx *arg = d;
    const EVP_CIPHER *ossl_evp;
    hc_EVP_CIPHER *hc_evp;

    hc_evp = arg->hc_memoize;

    /*
     * We lookup EVP_CIPHER *s by NID so that we don't fail to find a
     * symbol such as EVP_aes...() when libcrypto changes after build
     * time (e.g., updates, LD_LIBRARY_PATH/LD_PRELOAD).
     */
    ossl_evp = EVP_get_cipherbynid(arg->nid);
    if (ossl_evp == NULL) {
        (void) memset(hc_evp, 0, sizeof(*hc_evp));
#if HCRYPTO_FALLBACK
        *arg->hc_memoizep = arg->fallback;
#endif
        return;
    }

    /* Build the hc_EVP_CIPHER */
    hc_evp->nid = EVP_CIPHER_nid(ossl_evp); /* We would an hcrypto NIDs if we had them */
    hc_evp->block_size = EVP_CIPHER_block_size(ossl_evp);
    hc_evp->key_len = EVP_CIPHER_key_length(ossl_evp);
    hc_evp->iv_len = EVP_CIPHER_iv_length(ossl_evp);

    /*
     * We force hc_EVP_CipherInit_ex to always call our init() function,
     * otherwise we don't get a chance to call EVP_CipherInit_ex()
     * correctly.
     */
    hc_evp->flags = hc_EVP_CIPH_ALWAYS_CALL_INIT | arg->flags;

    /* Our cipher context */
    hc_evp->ctx_size = sizeof(struct ossl_cipher_ctx);

    /* Our wrappers */
    hc_evp->init = cipher_ctx_init;
    hc_evp->do_cipher = cipher_do_cipher;
    hc_evp->cleanup = cipher_cleanup;
    hc_evp->set_asn1_parameters = NULL;
    hc_evp->get_asn1_parameters = NULL;
    hc_evp->ctrl = cipher_ctrl;

    /* Our link to the OpenSSL EVP_CIPHER */
    hc_evp->app_data = (void *)ossl_evp;

    /* Finally, set the static hc_EVP_CIPHER * to the one we just built */
    *arg->hc_memoizep = hc_evp;
}
开发者ID:InvLim,项目名称:heimdal,代码行数:53,代码来源:evp-openssl.c

示例13: dtls1_enc

int dtls1_enc(SSL *s, int send)
	{
	SSL3_RECORD *rec;
	EVP_CIPHER_CTX *ds;
	unsigned long l;
	int bs,i,ii,j,k,n=0;
	const EVP_CIPHER *enc;

	if (send)
		{
		if (EVP_MD_CTX_md(s->write_hash))
			{
			n=EVP_MD_CTX_size(s->write_hash);
			if (n < 0)
				return -1;
			}
		ds=s->enc_write_ctx;
		rec= &(s->s3->wrec);
		if (s->enc_write_ctx == NULL)
			enc=NULL;
		else
			{
			enc=EVP_CIPHER_CTX_cipher(s->enc_write_ctx);
			if ( rec->data != rec->input)
				/* we can't write into the input stream */
#ifndef OPENSSL_SYS_WINDOWS
				TINYCLR_SSL_PRINTF("%s:%d: rec->data != rec->input\n",
					__FILE__, __LINE__);

#else
				TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR, "%s:%d: rec->data != rec->input\n",
					__FILE__, __LINE__);
#endif
			else if ( EVP_CIPHER_block_size(ds->cipher) > 1)
				{
				if (RAND_bytes(rec->input, EVP_CIPHER_block_size(ds->cipher)) <= 0)
					return -1;
				}
			}
		}
开发者ID:Sorcha,项目名称:NETMF-LPC,代码行数:40,代码来源:d1_enc.cpp

示例14: wi_cipher_block_size

wi_uinteger_t wi_cipher_block_size(wi_cipher_t *cipher) {
#ifdef WI_CIPHER_OPENSSL
	return EVP_CIPHER_block_size(cipher->cipher);
#endif
	
#ifdef WI_CIPHER_COMMONCRYPTO
	switch(cipher->type) {
		case WI_CIPHER_AES128:		return kCCBlockSizeAES128;
		case WI_CIPHER_3DES192:		return kCCBlockSize3DES;
		default:					return 0;
	}
#endif
}
开发者ID:ProfDrLuigi,项目名称:zanka,代码行数:13,代码来源:wi-cipher.c

示例15: cipher_by_id

/** Get required size for an encrypted buffer of the given plain text length.
 * @param plain_length length of the plain text buffer to encrypt
 * @return length of encrypted buffer required
 */
size_t
BufferEncryptor::encrypted_buffer_size(size_t plain_length)
{
#ifdef HAVE_LIBCRYPTO
  const EVP_CIPHER *evp_cipher = cipher_by_id(cipher_id_);

  const size_t iv_size = EVP_CIPHER_iv_length(evp_cipher);
  size_t block_size    = EVP_CIPHER_block_size(evp_cipher);

  return (((plain_length / block_size) + 1) * block_size) + iv_size;
#else
  throw std::runtime_error("Encryption not supported");
#endif
}
开发者ID:timn,项目名称:fawkes,代码行数:18,代码来源:crypto.cpp


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