Skip to content

Commit

Permalink
Add sample use of libscrypt.a and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gperciva committed Apr 19, 2019
1 parent c1d2e5f commit d393dc2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
9 changes: 9 additions & 0 deletions BUILDING
Expand Up @@ -15,6 +15,15 @@ Official scrypt tarball releases should build and run on any IEEE Std 1003.1
3. Provides /dev/urandom.


libscrypt
---------

To install the development library, run:

./configure --enable-libscrypt
make install


Platform-specific notes
-----------------------

Expand Down
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -113,6 +113,16 @@ int crypto_scrypt(const uint8_t *, size_t, const uint8_t *, size_t, uint64_t,
uint32_t, uint32_t, uint8_t *, size_t);
```

There is a sample of using `crypto_scrypt()` in `tests/libscrypt`. If you
installed `libscrypt`, you can compile that file and run the binary:

```
$ cd tests/libscrypt/
$ cc sample-libscrypt.c -lscrypt
$ ./a.out
crypto_scrypt(): success
```


Building
--------
Expand Down
33 changes: 33 additions & 0 deletions tests/libscrypt/sample-libscrypt.c
@@ -0,0 +1,33 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include "crypto_scrypt.h"

/* Parameters controlling memory usage and CPU time. */
#define N 16384
#define r 8
#define p 1

/* How much data should scrypt return? */
#define OUTPUT_BUFLEN 8

int main()
{
const char * passwd = "hunter2";
const char * salt = "DANGER -- this should be a random salt -- DANGER";
uint8_t output[OUTPUT_BUFLEN];
int exitcode;

exitcode = crypto_scrypt((const uint8_t *)passwd, strlen(passwd),
(const uint8_t*)salt, strlen(salt), N, r, p,
output, OUTPUT_BUFLEN);

/* Notify user of success / failure. */
if (exitcode == 0)
printf("crypto_scrypt(): success\n");
else
printf("crypto_scrypt(): failure %i\n", exitcode);

return (exitcode);
}

0 comments on commit d393dc2

Please sign in to comment.