Remove hash.c and stream.c for now.

This commit is contained in:
Frank Denis
2015-05-27 15:49:57 +02:00
parent a748029632
commit 4ea111bcb5
2 changed files with 0 additions and 128 deletions
-45
View File
@@ -1,45 +0,0 @@
/*
* GraxRabble
* Demo programs for libsodium.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sodium.h> /* library header */
#include "utils.h" /* utility functions shared by demos */
/*
* The library ships with a one-shot SHA-512 implementation. Simply allocate
* all desired data into a single continuous buffer.
*/
static void
hash(void)
{
unsigned char h[crypto_hash_BYTES]; /* hash output */
unsigned char m[MAX_INPUT_SIZE]; /* message */
size_t mlen; /* length */
puts("Example: crypto_hash\n");
mlen = prompt_input("Input your message > ", (char*)m, sizeof m);
putchar('\n');
printf("Hashing message with %s\n", crypto_hash_primitive());
crypto_hash(h, m, mlen);
fputs("Hash: ", stdout);
print_hex(h, sizeof h);
putchar('\n');
putchar('\n');
}
int
main(void)
{
sodium_init();
printf("Using LibSodium %s\n", sodium_version_string());
hash();
return 0;
}
-83
View File
@@ -1,83 +0,0 @@
/*
* GraxRabble
* Demo programs for libsodium.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sodium.h> /* library header */
#include "utils.h" /* utility functions shared by demos */
/*
* Stream utilizes a nonce to generate a sequence of bytes. The library has
* an internal function which XOR data and the stream into an encrypted result.
*
* Note that this method does not supply authentication. Try secretbox instead.
*
* Note that nonce must be different for each message since it provides
* change between each operation. It should be safe to use a counter
* instead of purely random data each time.
*/
static int
stream(void)
{
unsigned char k[crypto_stream_KEYBYTES]; /* secret key */
unsigned char n[crypto_stream_NONCEBYTES]; /* message nonce */
unsigned char m[MAX_INPUT_SIZE]; /* plain-text */
unsigned char c[MAX_INPUT_SIZE]; /* cipher-text */
size_t mlen; /* length */
int r;
puts("Example: crypto_stream\n");
memset(k, 0, sizeof k);
prompt_input("Input your key > ", (char*)k, sizeof k);
putchar('\n');
/* nonce must be generated per message, safe to send with message */
puts("Generating nonce...");
randombytes_buf(n, sizeof n);
fputs("Nonce: ", stdout);
print_hex(n, sizeof n);
putchar('\n');
putchar('\n');
mlen = prompt_input("Input your message > ", (char*)m, sizeof m);
putchar('\n');
printf("Encrypting with (xor) %s\n", crypto_stream_primitive());
crypto_stream_xor(c, m, mlen, n, k);
putchar('\n');
puts("Sending message...");
puts("Format: nonce::message");
fputs("Ciphertext: ", stdout);
print_hex(n, sizeof n);
fputs("::", stdout);
print_hex(c, mlen);
putchar('\n');
putchar('\n');
puts("Opening message...");
r = crypto_stream_xor(m, c, mlen, n, k);
print_verification(r);
if (r == 0)
printf("Plaintext: %s\n\n", m);
sodium_memzero(k, sizeof k); /* wipe sensitive data */
sodium_memzero(m, sizeof m);
sodium_memzero(c, sizeof c);
return r;
}
int
main(void)
{
sodium_init();
printf("Using LibSodium %s\n", sodium_version_string());
return stream() != 0;
}