本文整理汇总了C++中sodium_init函数的典型用法代码示例。如果您正苦于以下问题:C++ sodium_init函数的具体用法?C++ sodium_init怎么用?C++ sodium_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sodium_init函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, const char * argv[]) {
// Init sodium (currently not in use)
sodium_init();
if(sodium_init()) {
std::cout << "Starting to encode ...\n";
encode(argv[1], argv[2]);
std::cout << "Starting to decode ...\n";
decode(argv[2]);
}
return 0;
}
开发者ID:Sopamo,项目名称:m2p,代码行数:13,代码来源:main.cpp
示例2: main
int
main(void)
{
sodium_set_misuse_handler(NULL);
sodium_set_misuse_handler(misuse_handler);
sodium_set_misuse_handler(NULL);
assert(sodium_init() == 1);
(void) sodium_runtime_has_neon();
(void) sodium_runtime_has_sse2();
(void) sodium_runtime_has_sse3();
(void) sodium_runtime_has_ssse3();
(void) sodium_runtime_has_sse41();
(void) sodium_runtime_has_pclmul();
(void) sodium_runtime_has_aesni();
sodium_set_misuse_handler(misuse_handler);
#ifndef __EMSCRIPTEN__
sodium_misuse();
printf("Misuse handler returned\n");
#else
printf("misuse_handler()\n");
#endif
return 0;
}
开发者ID:luccasmenezes,项目名称:libsodium,代码行数:27,代码来源:sodium_core.c
示例3: config_encryption
//02 002
void config_encryption(const char *password, const char *method) {
SSLeay_add_all_algorithms();
sodium_init();
_method = encryption_method_from_string(method);
if (_method == ENCRYPTION_TABLE) {
get_table((unsigned char *) password);
cipher = CIPHER_TABLE;
} else if (_method == ENCRYPTION_SALSA20 || _method == ENCRYPTION_CHACHA20) {
cipher = CIPHER_SODIUM;
_key_len = 32;
unsigned char tmp[EVP_MAX_IV_LENGTH];;
EVP_BytesToKey(EVP_aes_256_cfb(), EVP_md5(), NULL, (unsigned char *)password,
strlen(password), 1, _key, tmp);
shadowsocks_key = _key;
} else {
cipher = CIPHER_OPENSSL;
const char *name = shadowsocks_encryption_names[_method];
if (_method == ENCRYPTION_RC4_MD5) {
name = "RC4";
}
_cipher = EVP_get_cipherbyname(name);
if (_cipher == NULL) {
// assert(0);
// TODO
printf("_cipher is nil! \r\nThe %s doesn't supported!\r\n please chose anthor!",name);
} else {
unsigned char tmp[EVP_MAX_IV_LENGTH];
_key_len = EVP_BytesToKey(_cipher, EVP_md5(), NULL, (unsigned char *)password,
strlen(password), 1, _key, tmp);
shadowsocks_key = _key;
}
// printf("%d\n", _key_len);
}
}
开发者ID:wongzigii,项目名称:shadowsocks-iOS,代码行数:36,代码来源:encrypt.c
示例4: main
int main(int argc,char **argv)
{
char *d;
if (!argv[0]) die_usage();
if (!argv[1]) die_usage();
d = argv[1];
umask(022);
if (mkdir(d,0755) == -1) die_fatal("unable to create directory",d,0);
if (chdir(d) == -1) die_fatal("unable to chdir to directory",d,0);
if (mkdir(".expertsonly",0700) == -1) die_fatal("unable to create directory",d,".expertsonly");
sodium_init();
crypto_box_keypair(pk,sk);
create(d,"publickey",pk,sizeof pk);
randombytes(noncekey,sizeof noncekey);
umask(077);
create(d,".expertsonly/secretkey",sk,sizeof sk);
create(d,".expertsonly/lock",lock,sizeof lock);
create(d,".expertsonly/noncekey",noncekey,sizeof noncekey);
create(d,".expertsonly/noncecounter",noncecounter,sizeof noncecounter);
return 0;
}
开发者ID:aburan28,项目名称:libchloride,代码行数:28,代码来源:curvecpmakekey.c
示例5: mechanism_t
zmq::curve_server_t::curve_server_t (session_base_t *session_,
const std::string &peer_address_,
const options_t &options_) :
mechanism_t (options_),
session (session_),
peer_address (peer_address_),
state (expect_hello),
expecting_zap_reply (false),
cn_nonce (1),
sync()
{
// Fetch our secret key from socket options
memcpy (secret_key, options_.curve_secret_key, crypto_box_SECRETKEYBYTES);
scoped_lock_t lock (sync);
#if defined(HAVE_TWEETNACL)
// allow opening of /dev/urandom
unsigned char tmpbytes[4];
randombytes(tmpbytes, 4);
#else
// todo check return code
sodium_init();
#endif
// Generate short-term key pair
const int rc = crypto_box_keypair (cn_public, cn_secret);
zmq_assert (rc == 0);
}
开发者ID:klnikita,项目名称:libzmq,代码行数:27,代码来源:curve_server.cpp
示例6: crypto_init
int crypto_init() {
if (-1 == sodium_init())
return 1;
randombytes_set_implementation(&randombytes_salsa20_implementation);
randombytes_stir();
return 0;
}
开发者ID:11liju,项目名称:ShadowVPN,代码行数:7,代码来源:crypto.c
示例7: main
int main() {
char *pw =ucmalloc(8);
char *pw2 =ucmalloc(8);
char *o = ucmalloc(8);
char *m = ucmalloc(8);
strcpy(pw, "xxxx");
strcpy(pw2, "xxxx");
strcpy(o, "xxxx");
strcpy(m, "xxxx");
if(sodium_init() == -1) return 1;
PCPCTX *ptx = ptx_new();
pcp_key_t *k = pcpkey_new ();
memcpy(k->owner, o, 8);
memcpy(k->mail, m, 8);
pcp_key_t *key = pcpkey_encrypt(ptx, k, pw);
int i;
for(i=0; i<3; i++)
mkinvalid_secret(ptx, key, i);
for(i=0; i<4; i++)
mkinvalid_public(ptx, key, i);
mkinvv(ptx, "testvault-invalidheader", 0);
mkinvv(ptx, "testvault-invalidversion", 1);
mkinvv(ptx, "testvault-invaliditemsize", 2);
mkinvv(ptx, "testvault-invaliditemtype", 3);
mkinvv(ptx, "testvault-invalidkeytype", 4);
return 0;
}
开发者ID:TLINDEN,项目名称:pcp,代码行数:34,代码来源:invalidkeys.c
示例8: createGUID
static char * createGUID()
{
sodium_init();
unsigned char out[crypto_hash_sha512_BYTES];
unsigned char sk[crypto_sign_SECRETKEYBYTES];
int valid_pow = 0;
while (valid_pow == 0){
//Generate a key pair
unsigned char pk[crypto_sign_PUBLICKEYBYTES];
unsigned char sk[crypto_sign_SECRETKEYBYTES];
crypto_sign_keypair(pk, sk);
//Sign the public key
const unsigned char * message = pk;
int message_len = crypto_sign_PUBLICKEYBYTES;
unsigned char signed_message[crypto_sign_BYTES + message_len];
unsigned long long signed_message_len;
crypto_sign(signed_message, &signed_message_len,
message, message_len, sk);
//Hash the signed key with sha512
crypto_hash_sha512(out, signed_message, signed_message_len);
char proof_of_work[32];
memcpy(proof_of_work, &out[32], 32);
char * pow = to_hex(proof_of_work, 3);
valid_pow = test_pow(pow);
}
to_hex(sk, 32);
return to_hex(sk, 32);
}
开发者ID:yynil,项目名称:OpenBazaar-Server,代码行数:34,代码来源:guidc.c
示例9: mechanism_t
zmq::curve_client_t::curve_client_t (const options_t &options_) :
mechanism_t (options_),
state (send_hello),
cn_nonce(1),
cn_peer_nonce(1),
sync()
{
int rc;
memcpy (public_key, options_.curve_public_key, crypto_box_PUBLICKEYBYTES);
memcpy (secret_key, options_.curve_secret_key, crypto_box_SECRETKEYBYTES);
memcpy (server_key, options_.curve_server_key, crypto_box_PUBLICKEYBYTES);
scoped_lock_t lock (sync);
#if defined(HAVE_TWEETNACL)
// allow opening of /dev/urandom
unsigned char tmpbytes[4];
randombytes(tmpbytes, 4);
#else
rc = sodium_init ();
zmq_assert (rc != -1);
#endif
// Generate short-term key pair
rc = crypto_box_keypair (cn_public, cn_secret);
zmq_assert (rc == 0);
}
开发者ID:HJoYer,项目名称:libzmq,代码行数:25,代码来源:curve_client.cpp
示例10: main
int main(void) {
sodium_init();
//create random chain key
unsigned char chain_key[crypto_auth_BYTES];
randombytes_buf(chain_key, crypto_auth_BYTES);
//print first chain key
printf("Chain key (%i Bytes):\n", crypto_auth_BYTES);
print_hex(chain_key, crypto_auth_BYTES, 30);
putchar('\n');
int status;
//derive message key from chain key
unsigned char message_key[crypto_auth_BYTES];
status = derive_message_key(message_key, chain_key);
sodium_memzero(chain_key, crypto_auth_BYTES);
if (status != 0) {
fprintf(stderr, "ERROR: Failed to derive message key. (%i)\n", status);
sodium_memzero(message_key, crypto_auth_BYTES);
return status;
}
//print message key
printf("Message key (%i Bytes):\n", crypto_auth_BYTES);
print_hex(message_key, crypto_auth_BYTES, 30);
putchar('\n');
sodium_memzero(message_key, crypto_auth_BYTES);
return EXIT_SUCCESS;
}
开发者ID:gitter-badger,项目名称:molch,代码行数:33,代码来源:message-key-derivation-test.c
示例11: tag
zmq::ctx_t::ctx_t () :
tag (ZMQ_CTX_TAG_VALUE_GOOD),
starting (true),
terminating (false),
reaper (NULL),
slot_count (0),
slots (NULL),
max_sockets (clipped_maxsocket (ZMQ_MAX_SOCKETS_DFLT)),
max_msgsz (INT_MAX),
io_thread_count (ZMQ_IO_THREADS_DFLT),
blocky (true),
ipv6 (false),
thread_priority (ZMQ_THREAD_PRIORITY_DFLT),
thread_sched_policy (ZMQ_THREAD_SCHED_POLICY_DFLT)
{
#ifdef HAVE_FORK
pid = getpid();
#endif
#ifdef ZMQ_HAVE_VMCI
vmci_fd = -1;
vmci_family = -1;
#endif
crypto_sync.lock ();
#if defined (ZMQ_USE_TWEETNACL)
// allow opening of /dev/urandom
unsigned char tmpbytes[4];
randombytes(tmpbytes, 4);
#elif defined (ZMQ_USE_LIBSODIUM)
int rc = sodium_init ();
zmq_assert (rc != -1);
#endif
crypto_sync.unlock ();
}
开发者ID:5igm4,项目名称:libzmq,代码行数:34,代码来源:ctx.cpp
示例12: _fact
void c_the_program::init_library_sodium() {
_fact(mo_file_reader::gettext("L_starting_lib_libsodium"));
if (sodium_init() == -1) {
_throw_error( std::runtime_error(mo_file_reader::gettext("L_lisodium_init_err")) );
}
_info(mo_file_reader::gettext("L_libsodium_ready"));
}
开发者ID:tigusoft,项目名称:galaxy42,代码行数:8,代码来源:the_program.cpp
示例13: main
int main(void) {
if (sodium_init() == -1) {
return -1;
}
return_status status = return_status_init();
//create buffers
buffer_t *master_key = buffer_create_on_heap(50, 50);
buffer_t *subkey1 = buffer_create_on_heap(60, 60);
buffer_t *subkey2 = buffer_create_on_heap(60, 60);
buffer_t *subkey1_copy = buffer_create_on_heap(60, 60);
int status_int = 0;
status_int = buffer_fill_random(master_key, master_key->buffer_length);
if (status_int != 0) {
throw(KEYDERIVATION_FAILED, "Failed to generate master key.");
}
printf("Master key:\n");
print_hex(master_key);
putchar('\n');
status = derive_key(subkey1, subkey1->buffer_length, master_key, 0);
throw_on_error(KEYDERIVATION_FAILED, "Failed to derive first subkey.");
printf("First subkey:\n");
print_hex(subkey1);
putchar('\n');
status = derive_key(subkey2, subkey2->buffer_length, master_key, 1);
throw_on_error(KEYDERIVATION_FAILED, "Failed to derive the second subkey.");
printf("Second subkey:\n");
print_hex(subkey2);
putchar('\n');
if (buffer_compare(subkey1, subkey2) == 0) {
throw(KEYGENERATION_FAILED, "Both subkeys are the same.");
}
status = derive_key(subkey1_copy, subkey1_copy->buffer_length, master_key, 0);
throw_on_error(KEYDERIVATION_FAILED, "Failed to derive copy of the first subkey.");
if (buffer_compare(subkey1, subkey1_copy) != 0) {
throw(INCORRECT_DATA, "Failed to reproduce subkey.");
}
cleanup:
buffer_destroy_from_heap_and_null_if_valid(master_key);
buffer_destroy_from_heap_and_null_if_valid(subkey1);
buffer_destroy_from_heap_and_null_if_valid(subkey2);
buffer_destroy_from_heap_and_null_if_valid(subkey1_copy);
on_error {
print_errors(&status);
}
return_status_destroy_errors(&status);
return status.status;
}
开发者ID:1984not-GmbH,项目名称:molch,代码行数:58,代码来源:key-derivation-test.c
示例14: main
int main () {
unsigned char hash[crypto_generichash_BYTES + 1] = {0};
unsigned char minhash[crypto_generichash_BYTES_MIN + 1] = {0};
unsigned char maxhash[crypto_generichash_BYTES_MAX + 1] = {0};
unsigned char key[crypto_generichash_KEYBYTES] = "123456789 123456789 123456789 12";
if (sodium_init() != 0) {
return -1;
}
size_t min_hex_maxlen = crypto_generichash_BYTES_MIN * 2 + 1;
size_t std_hex_maxlen = crypto_generichash_BYTES * 2 + 1;
size_t max_hex_maxlen = crypto_generichash_BYTES_MAX * 2 + 1;
unsigned char min_hex[min_hex_maxlen];
unsigned char std_hex[std_hex_maxlen];
unsigned char max_hex[max_hex_maxlen];
printf ("text: %s\n", MESSAGE);
crypto_generichash(minhash, crypto_generichash_BYTES_MIN,
MESSAGE, MESSAGE_LEN,
NULL, 0);
sodium_bin2hex (min_hex, min_hex_maxlen, minhash, crypto_generichash_BYTES_MIN);
printf ("min hash: %s\n", min_hex);
printf ("hash length is %d\n", strlen (minhash));
crypto_generichash(hash, crypto_generichash_BYTES,
MESSAGE, MESSAGE_LEN,
NULL, 0);
sodium_bin2hex (std_hex, std_hex_maxlen, hash, crypto_generichash_BYTES);
printf ("\nstd hash: %s\n", std_hex);
printf ("hash length is %d\n", strlen (hash));
crypto_generichash(maxhash, crypto_generichash_BYTES_MAX,
MESSAGE, MESSAGE_LEN,
NULL, 0);
sodium_bin2hex (max_hex, max_hex_maxlen, maxhash, crypto_generichash_BYTES_MAX);
printf ("\nmax hash: %s\n", max_hex);
printf ("hash length is %d\n", strlen (maxhash));
crypto_generichash(minhash, crypto_generichash_BYTES_MIN,
MESSAGE, MESSAGE_LEN,
key, sizeof key);
sodium_bin2hex (min_hex, min_hex_maxlen, minhash, crypto_generichash_BYTES_MIN);
printf ("\nkeyed min hash: %s\n", min_hex);
crypto_generichash(hash, crypto_generichash_BYTES,
MESSAGE, MESSAGE_LEN,
key, sizeof key);
sodium_bin2hex (std_hex, std_hex_maxlen, hash, crypto_generichash_BYTES);
printf ("keyed std hash: %s\n", std_hex);
crypto_generichash(maxhash, crypto_generichash_BYTES_MAX,
MESSAGE, MESSAGE_LEN,
key, sizeof key);
sodium_bin2hex (max_hex, max_hex_maxlen, maxhash, crypto_generichash_BYTES_MAX);
printf ("keyed max hash: %s\n", max_hex);
return 0;
}
开发者ID:jrmarino,项目名称:libsodium-ada,代码行数:58,代码来源:demo-c.c
示例15: main
int main(void) {
sodium_init();
//create random key
unsigned char key[crypto_secretbox_KEYBYTES];
randombytes_buf(key, crypto_secretbox_KEYBYTES);
//print key
printf("Key (%i Bytes):\n", crypto_secretbox_KEYBYTES);
print_hex(key, crypto_secretbox_KEYBYTES, 30);
putchar('\n');
//encrypted message
unsigned char ciphertext[500]; //TODO don't use fixed size buffer here
size_t ciphertext_length = 0;
int status;
status = encrypt(ciphertext, &ciphertext_length, key);
if (status != 0) {
fprintf(stderr, "ERROR: Failed to encrypt message. (%i)\n", status);
return status;
}
//print the ciphertext
printf("Ciphertext (packet, %zu Bytes):\n", ciphertext_length);
print_hex(ciphertext, ciphertext_length, 30);
putchar('\n');
puts("NOW DECRYPT -------------------------------------------------------------------\n");
unsigned char header[ciphertext_length];
size_t header_length = 0;
status = extract_header_without_verifying(
header,
&header_length,
ciphertext,
ciphertext_length);
if (status != 0) {
fprintf(stderr, "ERROR: Failed to extract header from packet. (%i)\n", status);
return status;
}
//print header
printf("Received header (%zu Bytes):\n%s\n\n", header_length, header);
//check header
if (sodium_memcmp(header, HEADER, sizeof(HEADER)) != 0) {
fprintf(stderr, "ERROR: Headers aren't the same!\n");
return -1;
}
return EXIT_SUCCESS;
}
开发者ID:gitter-badger,项目名称:molch,代码行数:56,代码来源:message-extract-header-test.c
示例16: luaopen_sodium
LUALIB_API int luaopen_sodium (lua_State *L) {
if (sodium_init() != 0) {
lua_pushstring(L, "Failed to initialize libsodium.");
return lua_error(L);
}
lua_newtable(L);
luaL_setfuncs(L, sodiumlib, 0);
return 1;
}
开发者ID:ayourtch,项目名称:lua-sodium,代码行数:10,代码来源:sodium.c
示例17: crypto_init
int
crypto_init(const char *password) {
if (sodium_init() == -1) {
return 1;
}
randombytes_set_implementation(&randombytes_salsa20_implementation);
randombytes_stir();
return crypto_generichash(secret_key, sizeof secret_key, (uint8_t*)password, strlen(password), NULL, 0);
}
开发者ID:gvsurenderreddy,项目名称:xTun,代码行数:11,代码来源:crypto.c
示例18: handshake
proto_functions_s* __stdcall handshake( host_functions_s *hf )
{
if (ASSERT(lan_engine::get(false) == nullptr))
{
if (sodium_init() == -1)
{
}
lan_engine::create( hf );
}
return &funcs;
}
开发者ID:kjradv,项目名称:Isotoxin,代码行数:13,代码来源:proto_lan.cpp
示例19: main
int main(void) {
sodium_init();
//create a user_store
user_store *store = user_store_create();
//check the content
buffer_t *list = user_store_list(store);
if (list->content_length != 0) {
fprintf(stderr, "ERROR: List of users is not empty.\n");
user_store_destroy(store);
buffer_destroy_from_heap(list);
return EXIT_FAILURE;
}
buffer_destroy_from_heap(list);
int status;
//create three users with prekeys and identity keys
//first alice
//alice identity key
buffer_t *alice_private_identity = buffer_create(crypto_box_SECRETKEYBYTES, crypto_box_SECRETKEYBYTES);
buffer_t *alice_public_identity = buffer_create(crypto_box_PUBLICKEYBYTES, crypto_box_PUBLICKEYBYTES);
status = generate_and_print_keypair(
alice_public_identity->content,
alice_private_identity->content,
"Alice",
"identity");
if (status != 0) {
fprintf(stderr, "ERROR: Failed to generate Alice's identity keypair.\n");
buffer_clear(alice_private_identity);
return status;
}
//alice prekeys
buffer_t *alice_private_prekeys = buffer_create(PREKEY_AMOUNT * crypto_box_SECRETKEYBYTES, PREKEY_AMOUNT * crypto_box_SECRETKEYBYTES);
buffer_t *alice_public_prekeys = buffer_create(PREKEY_AMOUNT * crypto_box_PUBLICKEYBYTES, PREKEY_AMOUNT * crypto_box_PUBLICKEYBYTES);
status = generate_prekeys(alice_private_prekeys, alice_public_prekeys);
if (status != 0) {
fprintf(stderr, "ERROR: Failed to generate Alice's prekeys.\n");
buffer_clear(alice_private_identity);
buffer_clear(alice_private_prekeys);
return status;
}
//make illegal access to the user store
printf("User store length: %zi\n", store->length); //The program should crash here!
user_store_destroy(store);
return EXIT_SUCCESS;
}
开发者ID:tiagogehring,项目名称:molch,代码行数:51,代码来源:crashtest-store.c
示例20: InitializeYojimbo
bool InitializeYojimbo()
{
g_defaultAllocator = new yojimbo::DefaultAllocator();
assert( yojimbo::NonceBytes == crypto_aead_chacha20poly1305_NPUBBYTES );
assert( yojimbo::KeyBytes == crypto_aead_chacha20poly1305_KEYBYTES );
assert( yojimbo::AuthBytes == crypto_aead_chacha20poly1305_ABYTES );
assert( yojimbo::KeyBytes == crypto_secretbox_KEYBYTES );
assert( yojimbo::MacBytes == crypto_secretbox_MACBYTES );
if ( !yojimbo::InitializeNetwork() )
return false;
return sodium_init() != -1;
}
开发者ID:CristianMarastoni,项目名称:libyojimbo,代码行数:15,代码来源:yojimbo.cpp
注:本文中的sodium_init函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论