Beispiel #1
0
static char *
wallet_encrypt_string(struct wallet    *wallet,
                      const char       *plaintext,
                      struct crypt_key *ckey)
{
   struct secure_area *sec;
   char cipherStr[1024];
   uint8 *cipher;
   char *hmac;
   char *res;
   size_t clen;
   size_t len;
   bool s;

   ASSERT(plaintext);

   len = strlen(plaintext) + 1;
   sec = secure_alloc(len);
   memcpy(sec->buf, plaintext, len);

   s = crypt_encrypt(ckey, sec, &cipher, &clen);
   ASSERT(s);

   str_snprintf_bytes(cipherStr, sizeof cipherStr, NULL, cipher, clen);
   hmac = wallet_hmac_string(cipher, clen, wallet->pass);
   res = safe_asprintf("%s-%s", cipherStr, hmac);
   free(hmac);

   free(cipher);
   secure_free(sec);

   return res;
}
Beispiel #2
0
void send_stream(int fd, const char *msg, uint32_t msg_size)
{
    char *compressed = wf_compress_query(msg);
    char *buffer = NULL;

#ifdef DEBUG
    if (crypt_is_ready())
        printf("%s==(%3u)=> ", compressed ? "##" : "==", msg_size);
    else
        printf("%s--(%3u)-> ", compressed ? "##" : "--", msg_size);
    printf("\033[1;31m%s\033[0m\n", msg);
#endif

    if (compressed != NULL && strstr(msg, "to='k01.warface'") == NULL )
    {
        msg_size = strlen(compressed);
        buffer = compressed;
    }
    else
    {
        buffer = strdup(msg);
        free(compressed);
        compressed = buffer;
    }

#ifdef USE_PROTECT
    struct stream_hdr hdr;

    hdr.magic = STREAM_MAGIC;
    hdr.se = SE_PLAIN;
    hdr.len = msg_size;

    if (crypt_is_ready())
    {
        hdr.se = SE_ENCRYPTED;
        crypt_encrypt((uint8_t *) buffer, msg_size);
    }

    SEND(fd, &hdr, sizeof (hdr));
#endif /* USE_PROTECT */

    SEND(fd, buffer, msg_size);

    free(compressed);
}
Beispiel #3
0
void test_sym_throughput(void)
{
	struct crypt *c; 
	int id	    = TC_AES128_HMAC_SHA2;
	uint64_t iv = 0;
	int dlen    = 1420;
	void *data;

	c   	      = setup_cipher(TYPE_SYM, id, 0);
	data	      = alloca(dlen);
	_state.s_dlen = dlen;
	memset(data, 0, dlen);

	printf("Encrypting %d bytes of data\n", dlen);

	speed_start(cipher_throughput);

	while (1) {
		crypt_encrypt(c, &iv, data, dlen);
		speed_add(1);
	}

	crypt_destroy(c);
}