add example outputs

pull/1/head
Avril 4 years ago
parent a5c59d108f
commit 4cdb3ac741
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -1,6 +1,15 @@
* libkhash - kana-hash * libkhash - kana-hash
Kana mnemonic hashes Kana mnemonic hashes
** Example output
Input is "uguu~" using the default salt.
| Algorithm | Output |
|--------------------+------------------------------------------------------------------|
| SHA256 | おシソまツアでぅせツモァだゅノびヲろぢォセつマぶけぁユねハァがゅ |
| CRC32 | わぼぢァ |
| CRC64 | づやワえぼちレこ |
| SHA256 (truncated) | おシソまツアで |
** Installation ** Installation
The dynamic library is built with ~Cargo~ and ~Rust~, and the cli example program is built with ~gcc~. The dynamic library is built with ~Cargo~ and ~Rust~, and the cli example program is built with ~gcc~.
@ -56,29 +65,29 @@
*** Example *** Example
To create a context To create a context
#+BEGIN_SRC c #+BEGIN_SRC c
#include <khash.h> #include <khash.h>
const char* input_salt = "salt!"; const char* input_salt = "salt!";
const char* input_data = "some data to hash". const char* input_data = "some data to hash".
khash_context ctx; khash_context ctx;
assert(khash_new_context(KHASH_ALGO_SHA256, KHASH_SALT_TYPE_SPECIFIC, input_salt, strlen(input_salt), &ctx) == KHASH_SUCCESS, "khash_new_context() failed."); assert(khash_new_context(KHASH_ALGO_SHA256, KHASH_SALT_TYPE_SPECIFIC, input_salt, strlen(input_salt), &ctx) == KHASH_SUCCESS, "khash_new_context() failed.");
#+END_SRC #+END_SRC
Find the buffer length we need. Find the buffer length we need.
#+BEGIN_SRC c #+BEGIN_SRC c
size_t length; size_t length;
assert(khash_length(&ctx, input_data, strlen(input_data), &length) == KHASH_SUCCESS, "khash_length() failed."); assert(khash_length(&ctx, input_data, strlen(input_data), &length) == KHASH_SUCCESS, "khash_length() failed.");
#+END_SRC #+END_SRC
Create the buffer and hash, then print the result to ~stdout~. Create the buffer and hash, then print the result to ~stdout~.
#+BEGIN_SRC c #+BEGIN_SRC c
char* buffer = alloca(length+1); char* buffer = alloca(length+1);
assert(khash_do(&ctx, input_data, strlen(input_data), buffer, length) == KHASH_SUCCESS, "khash_do() failed."); assert(khash_do(&ctx, input_data, strlen(input_data), buffer, length) == KHASH_SUCCESS, "khash_do() failed.");
buffer[length] = 0; // Ensure we have a NUL terminator. buffer[length] = 0; // Ensure we have a NUL terminator.
setlocale(LC_ALL, ""); //Ensure we can print UTF-8. setlocale(LC_ALL, ""); //Ensure we can print UTF-8.
printf("Kana hash: %s\n", buffer); printf("Kana hash: %s\n", buffer);
#+END_SRC #+END_SRC
*** Definitions *** Definitions

Loading…
Cancel
Save