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

C++ ctr_drbg_init函数代码示例

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

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



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

示例1: ngx_ssl_init

ngx_int_t
ngx_ssl_init(ngx_log_t *log)
{
    static unsigned char  ctr_drbg_custom[] = "nginx-polarssl";
    entropy_context       entropy;
    int                   sslerr;

    /* Initialize the PRNG */

    entropy_init(&entropy);
    sslerr = ctr_drbg_init(&ngx_ctr_drbg, entropy_func, &entropy,
                           ctr_drbg_custom, ngx_strlen(ctr_drbg_custom));
    if (sslerr != 0) {
        ngx_mbedtls_error(NGX_LOG_EMERG, log, 0, sslerr,
                           "ctr_drbg_init() failed");
        return NGX_ERROR;
    }

#if (NGX_THREADS)
    ngx_ctr_drbg_mutex = ngx_mutex_init(log, 0);
    if (ngx_ctr_drbg_mutex == NULL) {
        return NGX_ERROR;
    }
#endif

    return NGX_OK;
}
开发者ID:sbagmeijer,项目名称:nginx,代码行数:27,代码来源:ngx_event_mbedtls.c


示例2: rand_ctx_get

/*
 * Initialise the given ctr_drbg context, using a personalisation string and an
 * entropy gathering function.
 */
ctr_drbg_context * rand_ctx_get()
{
  static entropy_context ec = {0};
  static ctr_drbg_context cd_ctx = {0};
  static bool rand_initialised = false;

  if (!rand_initialised)
    {
      struct gc_arena gc = gc_new();
      struct buffer pers_string = alloc_buf_gc(100, &gc);

      /*
       * Personalisation string, should be as unique as possible (see NIST
       * 800-90 section 8.7.1). We have very little information at this stage.
       * Include Program Name, memory address of the context and PID.
       */
      buf_printf(&pers_string, "OpenVPN %0u %p %s", platform_getpid(), &cd_ctx, time_string(0, 0, 0, &gc));

      /* Initialise PolarSSL RNG, and built-in entropy sources */
      entropy_init(&ec);

      if (0 != ctr_drbg_init(&cd_ctx, entropy_func, &ec, BPTR(&pers_string), BLEN(&pers_string)))
        msg (M_FATAL, "Failed to initialize random generator");

      gc_free(&gc);
      rand_initialised = true;
  }

  return &cd_ctx;
}
开发者ID:DenisMishin,项目名称:openvpn,代码行数:34,代码来源:crypto_polarssl.c


示例3: entropy_init

/*
	shameless copy/paste from:
	https://polarssl.org/kb/how-to/generate-an-aes-key
*/
unsigned char *generatekey(char *pers, int size){
	ctr_drbg_context ctr_drbg = {0};
	entropy_context entropy = {0};
	int keysize = 0;
	unsigned char *key = NULL;	
	int ret = 0;

	//convert to bytes
	keysize = size / 8;

	entropy_init( &entropy );
	if((ret = ctr_drbg_init(&ctr_drbg, entropy_func, &entropy, (unsigned char *)pers,strlen(pers))) != 0 ){
		outputerror(DBG_ERROR,"%s\n","generatekey::failed to initialize random generator");
		return NULL;
	}
		
	key = (unsigned char *)malloc(keysize);
	if(key == NULL){
		outputerror(DBG_ERROR,"%s\n","generatekey::failed to malloc");
		return NULL;
	}
	
	if((ret = ctr_drbg_random(&ctr_drbg,key,keysize)) != 0 ){
		outputerror(DBG_ERROR,"%s\n","generatekey::failed to produce random data");
		return NULL;
	}

	entropy_free(&entropy);
	return key;
}
开发者ID:DiabloHorn,项目名称:cryptoshot,代码行数:34,代码来源:screenshot.c


示例4: TestAESCrypto

////////////////////////////////////////////////////////////////////////////
//
// AES Encryption / Decryption - ECB Blocks
//
////////////////////////////////////////////////////////////////////////////
status TestAESCrypto( void )
{
   uint8 ret;
   uint8 buffer[512]; // AES - CBC can take less than 256 bytes as input

   uint8 key[16];    // Key can be 16 bytes ~ 128 AES or 32 bytes 256 AES
   uint8 iv[16];     // iv fixed random value of 16 bytes
   uint8 updated_iv[16];

   entropy_init( &entropy );
   if( ( ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
                         (const unsigned char *) pers,
                          strlen( pers ) ) ) != 0 )
   {
      proj_printf( " failed\n  ! ctr_drbg_init returned -0x%x\n", -ret );
      return ( FAIL );
   }

   //DRBG test
   proj_printf("INF: DRBG test - generate Random number");
   PrngGenerateBytes( buffer, sizeof(buffer));
   print_buffer(buffer,sizeof(buffer));

   // Setting key, iv and buffer values
   memset(buffer, 0xA5, sizeof(buffer));
   print_buffer(buffer,sizeof(buffer));

   PrngGenerateBytes(key,sizeof(key));
   print_buffer(key,sizeof(key));

   PrngGenerateBytes(iv,sizeof(iv));
   print_buffer(iv,sizeof(iv));

   // AES -CBC test
   memcpy(updated_iv, iv, sizeof(iv));

   AESCryptCBC( key, sizeof(key), AES_ENCRYPT, updated_iv, sizeof(buffer), buffer, buffer );
   print_buffer(buffer, sizeof(buffer));

   AESCryptCBC( key, sizeof(key), AES_DECRYPT, iv, sizeof(buffer), buffer, buffer );
   print_buffer(buffer, sizeof(buffer));

   // AES - ECB
   AESCryptECB( key, sizeof(key), AES_ENCRYPT, buffer, buffer );
   print_buffer(buffer, sizeof(buffer));

   AESCryptECB( key, sizeof(key), AES_DECRYPT, buffer, buffer );
   print_buffer(buffer, sizeof(buffer));

   // AES - ECB Blocks
   AESCryptECB_Blocks( key, sizeof(key), AES_ENCRYPT, sizeof(buffer)/16, buffer, buffer );
   print_buffer(buffer, sizeof(buffer));

   AESCryptECB_Blocks( key, sizeof(key), AES_DECRYPT, sizeof(buffer)/16, buffer, buffer );
   print_buffer(buffer, sizeof(buffer));

   return ( PASS );
}
开发者ID:dileepkella85,项目名称:trunk,代码行数:63,代码来源:crypto.c


示例5: gtget_ssl_init

void gtget_ssl_init(connection_t * conn)
{
  char *clientcert = NULL;
  char *clientkey = NULL;
  const char *pers = "gtget";
  sslparam_t *ssl = calloc(1, sizeof(sslparam_t));
  
  if (!(conn->flags & GTGET_FLAG_INSECURE)) {
    char *cacertfile = alloca(strlen(conn->remote->host) + 5);
    char *servercert = NULL;

    strcpy(cacertfile, conn->remote->host);
    strcat(cacertfile, ".pem");

    if (!(servercert = tryopen_alt(conn, conn->caFile, cacertfile)))
      servercert = tryopen("cacerts.pem");
    if (!(servercert))
      die(conn, "can't open cacert", NULL);
    if (x509_crt_parse_file(&ssl->cacert, servercert))
      die(conn, "error reading cacert", servercert);
  }

  /* read and parse the client certificate if provided */
  if ((clientcert = tryopen_alt(conn, conn->ccFile, "clientcert.pem"))) {
    if (!(clientkey = tryopen_alt(conn, conn->ckFile, "clientkey.pem")))
      clientkey = clientcert;

    if (x509_crt_parse_file(&ssl->clicert, clientcert)) {
      die(conn, "error reading client certificate", clientcert);
      if (clientkey && pk_parse_public_keyfile(&ssl->pk, clientkey))
        die(conn, "error reading client key", clientkey);

    }
    write2f("using client cert: %s\n", clientcert);
    write2f("using client key:  %s\n", clientkey);
  }

  entropy_init(&ssl->entropy);
  if (0 != (ctr_drbg_init(&ssl->ctr_drbg, entropy_func, &ssl->entropy,
	  (const unsigned char *)pers, strlen(pers))))
    die(conn, "Seeding the random number generator failed", NULL);


  if (ssl_init(&ssl->ssl))
    die(conn, "error initializing SSL", NULL);

  ssl_set_endpoint(&ssl->ssl, SSL_IS_CLIENT);
  if ((conn->flags & GTGET_FLAG_INSECURE)) {
    ssl_set_authmode(&ssl->ssl, SSL_VERIFY_NONE);
  }
  ssl_set_ca_chain(&ssl->ssl, &ssl->cacert, NULL, conn->remote->host);
  ssl_set_authmode(&ssl->ssl, SSL_VERIFY_OPTIONAL);
  ssl_set_verify(&ssl->ssl, verify_cb, conn);
  ssl_set_ciphersuites(&ssl->ssl, ssl_list_ciphersuites());
  ssl_set_session(&ssl->ssl, &ssl->ssn);
  ssl_set_rng(&ssl->ssl, ctr_drbg_random, &ssl->ctr_drbg);
  conn->ssl = ssl;
}
开发者ID:tenchman,项目名称:gsclu,代码行数:58,代码来源:gtget_polarssl.c


示例6: init_random

int init_random(void) {
   /* Initialize the rng */
   entropy_init(&entropy);
   entropy_add_source(&entropy, tpm_entropy_source, NULL, 0);
   entropy_gather(&entropy);
   ctr_drbg_init(&ctr_drbg, entropy_func, &entropy, NULL, 0);
   ctr_drbg_set_prediction_resistance( &ctr_drbg, CTR_DRBG_PR_OFF );

   return 0;
}
开发者ID:0day-ci,项目名称:xen,代码行数:10,代码来源:vtpm.c


示例7: ssl_init_info

int ssl_init_info(int *server_fd,ssl_info *sslinfo)
{
    int ret;
    const char *pers = "ssl";
    x509_crt_init(&sslinfo->cacert );
    entropy_init(&sslinfo->entropy );
    if( ( ret = ctr_drbg_init( &sslinfo->ctr_drbg, entropy_func, &sslinfo->entropy,
                               (const unsigned char *) pers,
                               strlen( pers ) ) ) != 0 )
    {

        return -1;
    }
    if( ( ret = ssl_init( &sslinfo->ssl ) ) != 0 )
    {
        echo( " failed\n  ! ssl_init returned %d\n\n", ret );
        return -1;
    }

    ssl_set_endpoint( &sslinfo->ssl, SSL_IS_CLIENT );
    ssl_set_authmode( &sslinfo->ssl, SSL_VERIFY_OPTIONAL );
    ssl_set_ca_chain( &sslinfo->ssl, &sslinfo->cacert, NULL, "" );
    ssl_set_rng( &sslinfo->ssl, ctr_drbg_random, &sslinfo->ctr_drbg );
    ssl_set_bio( &sslinfo->ssl, net_recv, server_fd,net_send, server_fd );
    ssl_set_session(&sslinfo->ssl, &ssn);



    while((ret = ssl_handshake(&sslinfo->ssl))!=0)
    {
        if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
        {
            echo( " failed\n  ! ssl_handshake returned -0x%x\n\n", -ret );
            return -1;
        }
        //CPU sleep
        sleeps(1);
    }

    if((ret = ssl_get_verify_result( &sslinfo->ssl ) ) != 0 )
    {
       // echo( "Verifying peer X.509 certificate...failed \r\n" );
    }
    else
    {
        echo( " ok\n" );
    }
    //保存session加快握手速度
    if( ( ret = ssl_get_session( &sslinfo->ssl, &ssn ) ) != 0 )
    {
        //失败初始化
        memset(&ssn, 0, sizeof(ssl_session));
    }
    return 0;
}
开发者ID:MoZhonghua,项目名称:ngrok-c,代码行数:55,代码来源:sslbio.cpp


示例8: chiffrer_rsa

int chiffrer_rsa(char* data, char* sortie, int taille_data )
{
    FILE *f;
    int ret;
    size_t i;
	rsa_context rsa;
    entropy_context entropy;
    ctr_drbg_context ctr_drbg;
    char *pers = "rsa_encrypt";
	
    printf( "[i] Seeding the random number generator\n" );

    entropy_init( &entropy );
    if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
                               (unsigned char *) pers, strlen( pers ) ) ) != 0 )
    {
        printf( "[-] ctr_drbg_init returned %d\n", ret );
        goto exit;
    }

    printf( "[i] Reading private key\n" );


    rsa_init( &rsa, RSA_PKCS_V15, 0 );
    
    if( ( ret = mpi_read_string( &rsa.N, RSA_N_BASE, RSA_N ) ) != 0 ||
        ( ret = mpi_read_string( &rsa.D, RSA_D_BASE, RSA_D ) ) != 0 )
    {
        printf( "[-] mpi_read_file returned %d\n", ret );
        goto exit;
    }

    rsa.len = ( mpi_msb( &rsa.N ) + 7 ) >> 3;


    /*
     * Calculate the RSA encryption of the hash.
     */
    printf( "[i] Generating the RSA encrypted value (%d/%d)\n", rsa.len, taille_data );
    fflush( stdout );

    if( ( ret = rsa_pkcs1_encrypt( &rsa, ctr_drbg_random, &ctr_drbg,
                                   RSA_PRIVATE, taille_data,
                                   data, sortie ) ) != 0 )
    {
        printf( "[-] rsa_pkcs1_encrypt returned %d\n\n", ret );
        goto exit;
    }
    printf( "[i] Cryptogramme copie\n");

exit:
    return( ret );
}
开发者ID:azazel7,项目名称:chiffreur,代码行数:53,代码来源:chiffrer_rsa.c


示例9: enclave_main

void enclave_main(egate_t *g)
{
	int random;
	entropy_context ectx;
	ctr_drbg_context rctx;
	enclave_entropy_init(&ectx);
	ctr_drbg_init(&rctx, entropy_func, &ectx, NULL, 0);
	ctr_drbg_random(&rctx, (unsigned char *)&random, sizeof(int));
	eg_printf(g, 
		  "Generated random number 0x%x in the enclave.\n", random);
	eg_exit(g, 0);
}
开发者ID:patrickb314,项目名称:janusSGX,代码行数:12,代码来源:egate-random.c


示例10: ctr_drbg_init

int cCtrDrbgContext::Initialize(const void * a_Custom, size_t a_CustomSize)
{
	if (m_IsValid)
	{
		// Already initialized
		return 0;
	}
	
	int res = ctr_drbg_init(&m_CtrDrbg, entropy_func, &(m_EntropyContext->m_Entropy), reinterpret_cast<const unsigned char *>(a_Custom), a_CustomSize);
	m_IsValid = (res == 0);
	return res;
}
开发者ID:36451,项目名称:MCServer,代码行数:12,代码来源:CtrDrbgContext.cpp


示例11: ms_dtls_srtp_initialise_polarssl_dtls_context

static int ms_dtls_srtp_initialise_polarssl_dtls_context(DtlsPolarsslContext *dtlsContext, MSDtlsSrtpParams *params, RtpSession *s){
	int ret;
	enum DTLS_SRTP_protection_profiles dtls_srtp_protection_profiles[2] = {SRTP_AES128_CM_HMAC_SHA1_80, SRTP_AES128_CM_HMAC_SHA1_32};
	
	memset( &(dtlsContext->ssl), 0, sizeof( ssl_context ) );
	//memset( &(dtlsContext->saved_session), 0, sizeof( ssl_session ) );
	ssl_cookie_init( &(dtlsContext->cookie_ctx) );
	x509_crt_init( &(dtlsContext->crt) );
	entropy_init( &(dtlsContext->entropy) );
	ctr_drbg_init( &(dtlsContext->ctr_drbg), entropy_func, &(dtlsContext->entropy), NULL, 0 );
	
	/* initialise certificate */
	ret = x509_crt_parse( &(dtlsContext->crt), (const unsigned char *) params->pem_certificate, strlen( params->pem_certificate ) );
	if( ret < 0 ) {
		return ret;
	}
	
	ret =  pk_parse_key( &(dtlsContext->pkey), (const unsigned char *) params->pem_pkey, strlen( params->pem_pkey ), NULL, 0 );
	if( ret != 0 ) {
		return ret;
	}

	/* ssl setup */
	ssl_init(&(dtlsContext->ssl));
	if( ret < 0 ) {
		return ret;
	}

	if (params->role == MSDtlsSrtpRoleIsClient) {
		ssl_set_endpoint(&(dtlsContext->ssl), SSL_IS_CLIENT);
	} else if (params->role == MSDtlsSrtpRoleIsServer) {
		ssl_set_endpoint(&(dtlsContext->ssl), SSL_IS_SERVER);
	}
	ssl_set_transport(&(dtlsContext->ssl), SSL_TRANSPORT_DATAGRAM);
	ssl_set_dtls_srtp_protection_profiles(  &(dtlsContext->ssl), dtls_srtp_protection_profiles, 2 ); /* TODO: get param from caller to select available profiles */

	/* set CA chain */
	ssl_set_authmode( &(dtlsContext->ssl), SSL_VERIFY_OPTIONAL ); /* this will force server to send his certificate to client as we need it to compute the fingerprint */
	ssl_set_rng(  &(dtlsContext->ssl), ctr_drbg_random, &(dtlsContext->ctr_drbg) );
	ssl_set_ca_chain( &(dtlsContext->ssl), &(dtlsContext->crt), NULL, NULL );
	ssl_set_own_cert( &(dtlsContext->ssl), &(dtlsContext->crt), &(dtlsContext->pkey) );
	if (params->role == MSDtlsSrtpRoleIsServer) {
		ssl_cookie_setup( &(dtlsContext->cookie_ctx), ctr_drbg_random, &(dtlsContext->ctr_drbg) );
		ssl_set_dtls_cookies( &(dtlsContext->ssl), ssl_cookie_write, ssl_cookie_check, &(dtlsContext->cookie_ctx) );
		ssl_session_reset( &(dtlsContext->ssl) );
		ssl_set_client_transport_id(&(dtlsContext->ssl), (const unsigned char *)(&(s->snd.ssrc)), 4);
	}

	ms_mutex_init(&dtlsContext->ssl_context_mutex, NULL);

	return 0;

}
开发者ID:krieger-od,项目名称:mediastreamer2,代码行数:53,代码来源:dtls_srtp.c


示例12: entropy_init

uint8_t *rsa_apply(uint8_t *input, int inlen, int *outlen, int mode) {
  rsa_context trsa;
  const char *pers = "rsa_encrypt";
  int rc;

  entropy_context entropy;
  ctr_drbg_context ctr_drbg;
  entropy_init(&entropy);
  if ((rc = ctr_drbg_init(&ctr_drbg, entropy_func, &entropy, (const unsigned char *)pers,
                          strlen(pers))) != 0)
    debug(1, "ctr_drbg_init returned %d\n", rc);

  rsa_init(&trsa, RSA_PKCS_V21, POLARSSL_MD_SHA1); // padding and hash id get overwritten
  // BTW, this seems to reset a lot of parameters in the rsa_context
  rc = x509parse_key(&trsa, (unsigned char *)super_secret_key, strlen(super_secret_key), NULL, 0);
  if (rc != 0)
    debug(1, "Error %d reading the private key.");

  uint8_t *out = NULL;

  switch (mode) {
  case RSA_MODE_AUTH:
    trsa.padding = RSA_PKCS_V15;
    trsa.hash_id = POLARSSL_MD_NONE;
    debug(2, "rsa_apply encrypt");
    out = malloc(trsa.len);
    rc = rsa_pkcs1_encrypt(&trsa, ctr_drbg_random, &ctr_drbg, RSA_PRIVATE, inlen, input, out);
    if (rc != 0)
      debug(1, "rsa_pkcs1_encrypt error %d.", rc);
    *outlen = trsa.len;
    break;
  case RSA_MODE_KEY:
    debug(2, "rsa_apply decrypt");
    trsa.padding = RSA_PKCS_V21;
    trsa.hash_id = POLARSSL_MD_SHA1;
    out = malloc(trsa.len);
#if POLARSSL_VERSION_NUMBER >= 0x01020900
    rc = rsa_pkcs1_decrypt(&trsa, ctr_drbg_random, &ctr_drbg, RSA_PRIVATE, (size_t *)outlen, input,
                           out, trsa.len);
#else
    rc = rsa_pkcs1_decrypt(&trsa, RSA_PRIVATE, outlen, input, out, trsa.len);
#endif
    if (rc != 0)
      debug(1, "decrypt error %d.", rc);
    break;
  default:
    die("bad rsa mode");
  }
  rsa_free(&trsa);
  debug(2, "rsa_apply exit");
  return out;
}
开发者ID:Havelock-Vetinari,项目名称:shairport-sync,代码行数:52,代码来源:common.c


示例13: mrb_ctrdrbg_initialize

static mrb_value mrb_ctrdrbg_initialize(mrb_state *mrb, mrb_value self) {
  ctr_drbg_context *ctr_drbg;
  entropy_context *entropy_p;
  mrb_value entp, pers;
  int ret;

  ctr_drbg = (ctr_drbg_context *)DATA_PTR(self);
  if (ctr_drbg) {
    mrb_free(mrb, ctr_drbg);
  }
  DATA_TYPE(self) = &mrb_ctr_drbg_type;
  DATA_PTR(self) = NULL;

  mrb_get_args(mrb, "o|S", &entp, &pers);

  if (mrb_type(entp) != MRB_TT_DATA) {
    mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
  }
  entropy_p = DATA_CHECK_GET_PTR(mrb, entp, &mrb_entropy_type, entropy_context);

  ctr_drbg = (ctr_drbg_context *)mrb_malloc(mrb, sizeof(ctr_drbg_context));
  DATA_PTR(self) = ctr_drbg;

  if (mrb_string_p(pers)) {
    mrb_iv_set(mrb, self, mrb_intern_lit(mrb, "@pers"), pers);
    ret = ctr_drbg_init(ctr_drbg, entropy_func, entropy_p, RSTRING_PTR(pers), RSTRING_LEN(pers));
  } else {
    ret = ctr_drbg_init(ctr_drbg, entropy_func, entropy_p, NULL, 0 );
  }

  if (ret == POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED ) {
    mrb_raise(mrb, E_RUNTIME_ERROR, "Could not initialize entropy source");	
  }

  return self;
}
开发者ID:toch,项目名称:mruby-polarssl,代码行数:36,代码来源:polarssl.c


示例14: getTickCount

void CTTLS::initEntropy() {
    if(iEntropyInicialized)return;
    iEntropyInicialized=1;
    int ret;
    char *getEntropyFromZRTP_tmp(unsigned char *p, int iBytes);
    unsigned char br[64];

    unsigned int getTickCount();
    unsigned int ui=getTickCount();

    entropy_init( &((T_SSL*)pSSL)->entropy );
    if( ( ret = ctr_drbg_init( &((T_SSL*)pSSL)->ctr_drbg, entropy_func, &((T_SSL*)pSSL)->entropy,
                               (unsigned char *) getEntropyFromZRTP_tmp(&br[0],63), 63 ) ) != 0 )
    {
        tivi_slog( " failed\n  ! ctr_drbg_init returned %d", ret );
    }
    printf("[init tls entrpoy sp=%d ms]\n",getTickCount()-ui);
}
开发者ID:JgdshSeerm,项目名称:silent-phone-android,代码行数:18,代码来源:CTTLS.cpp


示例15: SSL_library_init

int SSL_library_init() {
  char custom_data[200];
  unsigned char custom_data_md5[16];
  int custom_data_size;

  entropy_init(&g_entropy_context);

  /* Use collection of MAC addresses as custom data */
  custom_data_size = get_custom_data(custom_data, sizeof(custom_data));

  /* Since PolarSSL limits size of custom data use its MD5 */
  md5((unsigned char*)custom_data, custom_data_size, custom_data_md5);
  ctr_drbg_init(&g_ctr_drbg_context, entropy_func, &g_entropy_context,
                custom_data_md5, sizeof(custom_data_md5));

  /* SSL_library_init() always returns "1" */
  return 1;
}
开发者ID:AustinHunting,项目名称:polar,代码行数:18,代码来源:polarssl_compat.c


示例16: http_ssl_connect

void http_ssl_connect( struct HTTP* http )
{
	/** SSL init */
	entropy_init( &http->ssl.entropy );
	http->last_result = ctr_drbg_init( &http->ssl.ctr_drbg, entropy_func, &http->ssl.entropy, (unsigned char*)"HTTP_SSL", 8 );
	if ( http->last_result != 0 )
	{
		/** Entropy init failed */
		http->error.errorId = HTTP_ERROR_SSL_ENTROPY_INIT_FAILED;
		http->error.line = __LINE__;
		http->error.file = __FILE__;
		return;
	}

	memset( &http->ssl.ssl_session, 0, sizeof( ssl_session ) );
	memset( &http->ssl.ssl, 0, sizeof( ssl_context ) );

	http_raw_connect( http );
	if ( http->last_result != 0 )
	{
		/** Connect failed */
		return;
	}

	http->last_result = ssl_init( &http->ssl.ssl );
	if ( http->last_result != 0 )
	{
		/** SSL init failed */
		http->error.errorId = HTTP_ERROR_SSL_INIT_FAILED;
		http->error.line = __LINE__;
		http->error.file = __FILE__;
		return;
	}
	ssl_set_endpoint( &http->ssl.ssl, SSL_IS_CLIENT );
	ssl_set_authmode( &http->ssl.ssl, HTTP_SSL_VERIFY_MODE );

	ssl_set_rng( &http->ssl.ssl, ctr_drbg_random, &http->ssl.ctr_drbg );

	/** Insert debug function here */
	ssl_set_dbg( &http->ssl.ssl, NULL, stdout );
	ssl_set_bio( &http->ssl.ssl, net_recv, &http->socket, net_send, &http->socket );

	ssl_set_session( &http->ssl.ssl, &http->ssl.ssl_session );
}
开发者ID:RalfHerzog,项目名称:CoLiBro,代码行数:44,代码来源:http_ssl.c


示例17: init_ssl_module

/* Initialize SSL library
 */
int init_ssl_module(char *logfile) {
	ssl_error_logfile = logfile;

	rsa_init(&rsa, RSA_PKCS_V15, 0);

	entropy_init(&entropy);
	ctr_drbg_init(&ctr_drbg, entropy_func, &entropy, (unsigned char*)"Hiawatha_RND", 10);
	ctr_drbg_set_prediction_resistance(&ctr_drbg, CTR_DRBG_PR_OFF);

	ssl_cache_init(&cache);
	ssl_cache_set_max_entries(&cache, 100);

	if (pthread_mutex_init(&random_mutex, NULL) != 0) {
		return -1;
	} else if (pthread_mutex_init(&cache_mutex, NULL) != 0) {
		return -1;
	}

	return 0;
}
开发者ID:BuGlessRB,项目名称:hiawatha,代码行数:22,代码来源:ssl.c


示例18: encrypt

string encrypt(string plaintext, unsigned char key[32]) {
	unsigned char IV[16];
	ctr_drbg_context ctr_drbg;
	entropy_context entropy;
	char *pers = "aes_generate_key";
	entropy_init(&entropy);
	unsigned char buff[64], buff_out[64];
	memset(buff, 0, sizeof(buff));
	for(int i=0; i<plaintext.length(); ++i) {
		buff[i] = plaintext[i];
}
	int ret;
    if ((ret = ctr_drbg_init(&ctr_drbg,entropy_func,&entropy,(unsigned char*)pers, strlen(pers))) != 0)
    {
	printf("Failed\n");
	return 0;
    }
    if((ret = ctr_drbg_random( &ctr_drbg,IV,16)) !=0)
    {
	printf("Failed\n");
	return 0;
    }
  
	string en;
	for(int i=0; i<16; ++i)
    	en.push_back(IV[i]);
    	  
    aes_context enc_ctx;
    
    aes_setkey_enc(&enc_ctx, key, 256);
    
    aes_crypt_cbc(&enc_ctx, AES_ENCRYPT, 64, IV, buff, buff_out);
    
    
 
    for(int i=0; i<64; ++i) {
		en.push_back(buff_out[i]);
	}
    return en;
}
开发者ID:anantk17,项目名称:ntc-assg,代码行数:40,代码来源:crypto.cpp


示例19: polarssl_connect_step1

static CURLcode
polarssl_connect_step1(struct connectdata *conn,
                       int sockindex)
{
  struct Curl_easy *data = conn->data;
  struct ssl_connect_data* connssl = &conn->ssl[sockindex];
  const char *capath = SSL_CONN_CONFIG(CApath);
  const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
    conn->host.name;
  const long int port = SSL_IS_PROXY() ? conn->port : conn->remote_port;
  int ret = -1;
  char errorbuf[128];
  errorbuf[0]=0;

  /* PolarSSL only supports SSLv3 and TLSv1 */
  if(SSL_CONN_CONFIG(version) == CURL_SSLVERSION_SSLv2) {
    failf(data, "PolarSSL does not support SSLv2");
    return CURLE_SSL_CONNECT_ERROR;
  }

#ifdef THREADING_SUPPORT
  entropy_init_mutex(&entropy);

  if((ret = ctr_drbg_init(&BACKEND->ctr_drbg, entropy_func_mutex, &entropy,
                          NULL, 0)) != 0) {
    error_strerror(ret, errorbuf, sizeof(errorbuf));
    failf(data, "Failed - PolarSSL: ctr_drbg_init returned (-0x%04X) %s\n",
          -ret, errorbuf);
  }
#else
  entropy_init(&BACKEND->entropy);

  if((ret = ctr_drbg_init(&BACKEND->ctr_drbg, entropy_func, &BACKEND->entropy,
                          NULL, 0)) != 0) {
    error_strerror(ret, errorbuf, sizeof(errorbuf));
    failf(data, "Failed - PolarSSL: ctr_drbg_init returned (-0x%04X) %s\n",
          -ret, errorbuf);
  }
#endif /* THREADING_SUPPORT */

  /* Load the trusted CA */
  memset(&BACKEND->cacert, 0, sizeof(x509_crt));

  if(SSL_CONN_CONFIG(CAfile)) {
    ret = x509_crt_parse_file(&BACKEND->cacert,
                              SSL_CONN_CONFIG(CAfile));

    if(ret<0) {
      error_strerror(ret, errorbuf, sizeof(errorbuf));
      failf(data, "Error reading ca cert file %s - PolarSSL: (-0x%04X) %s",
            SSL_CONN_CONFIG(CAfile), -ret, errorbuf);

      if(SSL_CONN_CONFIG(verifypeer))
        return CURLE_SSL_CACERT_BADFILE;
    }
  }

  if(capath) {
    ret = x509_crt_parse_path(&BACKEND->cacert, capath);

    if(ret<0) {
      error_strerror(ret, errorbuf, sizeof(errorbuf));
      failf(data, "Error reading ca cert path %s - PolarSSL: (-0x%04X) %s",
            capath, -ret, errorbuf);

      if(SSL_CONN_CONFIG(verifypeer))
        return CURLE_SSL_CACERT_BADFILE;
    }
  }

  /* Load the client certificate */
  memset(&BACKEND->clicert, 0, sizeof(x509_crt));

  if(SSL_SET_OPTION(cert)) {
    ret = x509_crt_parse_file(&BACKEND->clicert,
                              SSL_SET_OPTION(cert));

    if(ret) {
      error_strerror(ret, errorbuf, sizeof(errorbuf));
      failf(data, "Error reading client cert file %s - PolarSSL: (-0x%04X) %s",
            SSL_SET_OPTION(cert), -ret, errorbuf);

      return CURLE_SSL_CERTPROBLEM;
    }
  }

  /* Load the client private key */
  if(SSL_SET_OPTION(key)) {
    pk_context pk;
    pk_init(&pk);
    ret = pk_parse_keyfile(&pk, SSL_SET_OPTION(key),
                           SSL_SET_OPTION(key_passwd));
    if(ret == 0 && !pk_can_do(&pk, POLARSSL_PK_RSA))
      ret = POLARSSL_ERR_PK_TYPE_MISMATCH;
    if(ret == 0)
      rsa_copy(&BACKEND->rsa, pk_rsa(pk));
    else
      rsa_free(&BACKEND->rsa);
    pk_free(&pk);

//.........这里部分代码省略.........
开发者ID:sshyran,项目名称:curl,代码行数:101,代码来源:polarssl.c


示例20: main

int main( int argc, char *argv[] )
{
    FILE *f;

    int ret;
    size_t n, buflen;
    int server_fd = -1;

    unsigned char *p, *end;
    unsigned char buf[2048];
    unsigned char hash[20];
    const char *pers = "dh_client";

    entropy_context entropy;
    ctr_drbg_context ctr_drbg;
    rsa_context rsa;
    dhm_context dhm;
    aes_context aes;

    ((void) argc);
    ((void) argv);

    memset( &rsa, 0, sizeof( rsa ) );
    memset( &dhm, 0, sizeof( dhm ) );

    /*
     * 1. Setup the RNG
     */
    printf( "\n  . Seeding the random number generator" );
    fflush( stdout );

    entropy_init( &entropy );
    if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
                               (const unsigned char *) pers,
                               strlen( pers ) ) ) != 0 )
    {
        printf( " failed\n  ! ctr_drbg_init returned %d\n", ret );
        goto exit;
    }

    /*
     * 2. Read the server's public RSA key
     */
    printf( "\n  . Reading public key from rsa_pub.txt" );
    fflush( stdout );

    if( ( f = fopen( "rsa_pub.txt", "rb" ) ) == NULL )
    {
        ret = 1;
        printf( " failed\n  ! Could not open rsa_pub.txt\n" \
                "  ! Please run rsa_genkey first\n\n" );
        goto exit;
    }

    rsa_init( &rsa, RSA_PKCS_V15, 0 );

    if( ( ret = mpi_read_file( &rsa.N, 16, f ) ) != 0 ||
        ( ret = mpi_read_file( &rsa.E, 16, f ) ) != 0 )
    {
        printf( " failed\n  ! mpi_read_file returned %d\n\n", ret );
        goto exit;
    }

    rsa.len = ( mpi_msb( &rsa.N ) + 7 ) >> 3;

    fclose( f );

    /*
     * 3. Initiate the connection
     */
    printf( "\n  . Connecting to tcp/%s/%d", SERVER_NAME,
                                             SERVER_PORT );
    fflush( stdout );

    if( ( ret = net_connect( &server_fd, SERVER_NAME,
                                         SERVER_PORT ) ) != 0 )
    {
        printf( " failed\n  ! net_connect returned %d\n\n", ret );
        goto exit;
    }

    /*
     * 4a. First get the buffer length
     */
    printf( "\n  . Receiving the server's DH parameters" );
    fflush( stdout );

    memset( buf, 0, sizeof( buf ) );

    if( ( ret = net_recv( &server_fd, buf, 2 ) ) != 2 )
    {
        printf( " failed\n  ! net_recv returned %d\n\n", ret );
        goto exit;
    }

    n = buflen = ( buf[0] << 8 ) | buf[1];
    if( buflen < 1 || buflen > sizeof( buf ) )
    {
        printf( " failed\n  ! Got an invalid buffer length\n\n" );
        goto exit;
//.........这里部分代码省略.........
开发者ID:451506709,项目名称:automated_machine,代码行数:101,代码来源:dh_client.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ ctrc_begind函数代码示例发布时间:2022-05-30
下一篇:
C++ ctr_build_number_from_float函数代码示例发布时间: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