Пример #1
0
  		~CTomcryptInternals(void)
  		{
  			int ErrorCode;

  	    ErrorCode = unregister_hash(&sha256_desc);
  	    if (ErrorCode == -1)
  	    {
  	    	std::cerr << "Cannot unregister SHA2 hash." << std::endl;
  	    }

  	    ErrorCode = fortuna_done(&mRandomGenerator);
  	    if (ErrorCode != CRYPT_OK)
  	    {
  	    	std::cerr << "Cannot close random generator: " << error_to_string(ErrorCode) << std::endl;
  	    }

  	    ErrorCode = unregister_prng(&fortuna_desc);
  	    if (ErrorCode == -1)
  	    {
  	    	std::cerr << "Cannot unregister random generator fortuna cipher." << std::endl;
  	    }

  	    ErrorCode = unregister_cipher(&rijndael_desc);
  	    if (ErrorCode == -1)
  	    {
  	    	std::cerr << "Cannot unregister AES cipher." << std::endl;
  	    }

  	    return;
  		}
Пример #2
0
/** done(userdata) */
static int Ldone(lua_State* L) {
    prng_state* prng = luaL_checkudata(L, 1, MYTYPE);
    int status = fortuna_done(prng);
    if (status != CRYPT_OK) {
        lua_pushnil(L);
        lua_pushstring(L, error_to_string(status));
    }
    return 0;
}
Пример #3
0
/** Generates and returns a new (privkey, pubkey) ECDH key pair.
 * Keys are represented as Lua strings, the private one under a libtomcrypt
 * proprietary format, the public one under X9.63 format. */
static int lnew( lua_State *L) {
    prng_state prng;
    int prng_initialized = 0;
    ecc_key key;

    int idx = find_prng("fortuna");
    if( -1 == idx) goto failure;
    if( CRYPT_OK != rng_make_prng( ENTROPY, idx, & prng, NULL)) goto failure;
    prng_initialized=1;

    /* Generate the 512 bits ECC key in privkey. */
    if( CRYPT_OK != ecc_make_key( & prng, idx, 64, & key)) goto failure;

    /* Buffer will hold both the private and public key transiently,
     * until each of them is transformed into a Lua string. */
    unsigned char buff [BUFF_SIZE];
    unsigned long buff_len = BUFF_SIZE;

    /* Push the string representation of privkey (tomcrypt's proprietary format). */
    if( CRYPT_OK != ecc_export( buff, & buff_len, PK_PRIVATE, & key)) goto failure;
    lua_pushlstring( L, (const char*) buff, buff_len);

    /* Push the string representation of pubkey (ANSI X9.63 format, which only
     * supports public keys. This is the format expected by the server). */
    if( CRYPT_OK != ecc_ansi_x963_export( & key, buff, & buff_len)) goto failure;
    lua_pushlstring( L, (const char *) buff, buff_len);

    fortuna_done( & prng);
    return 2;

    failure:
    /* TODO: release resources */
    if( prng_initialized) fortuna_done( & prng);
    lua_pushnil( L);
    lua_pushstring( L, "error");
    return 2;
}
Пример #4
0
static int sqlcipher_ltc_deactivate(void *ctx) {
#ifndef SQLCIPHER_LTC_NO_MUTEX_RAND
  sqlite3_mutex_enter(ltc_rand_mutex);
#endif
  ltc_ref_count--;
  if(ltc_ref_count == 0){
    fortuna_done(&prng);
    sqlcipher_memset((void *)&prng, 0, sizeof(prng));
#ifndef SQLCIPHER_LTC_NO_MUTEX_RAND
    sqlite3_mutex_leave(ltc_rand_mutex);
    sqlite3_mutex_free(ltc_rand_mutex);
    ltc_rand_mutex = NULL;
#endif
  }
#ifndef SQLCIPHER_LTC_NO_MUTEX_RAND
  else {
    sqlite3_mutex_leave(ltc_rand_mutex);
  }
#endif    
  return SQLITE_OK;
}
Пример #5
0
static int sqlcipher_ltc_deactivate(void *ctx) {
  ltc_ctx *ltc = (ltc_ctx*)ctx;
  fortuna_done(&(ltc->prng));
}