diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-06-16 22:57:16 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-06-17 20:49:05 +0200 |
commit | 6b060c1dc5486cbf51f13d168c442e7df116b26c (patch) | |
tree | 45ab36ae9f4a405c22dc082b226c361e886fe726 /userspace | |
parent | 5797051e8b1f3ac4d6cc5edf181a04536b496d3d (diff) | |
download | cryptodev-linux-6b060c1dc5486cbf51f13d168c442e7df116b26c.tar.gz cryptodev-linux-6b060c1dc5486cbf51f13d168c442e7df116b26c.tar.xz cryptodev-linux-6b060c1dc5486cbf51f13d168c442e7df116b26c.zip |
Use current_euid() and task_pid_nr(current) to get identifiers for owners (for imposed limits).
Diffstat (limited to 'userspace')
-rw-r--r-- | userspace/setkey.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/userspace/setkey.c b/userspace/setkey.c new file mode 100644 index 0000000..2642b90 --- /dev/null +++ b/userspace/setkey.c @@ -0,0 +1,63 @@ +/* + * Demo on how to use /dev/crypto device for HMAC. + * + * Placed under public domain. + * + */ +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <time.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include "../ncr.h" +#include <stdlib.h> + + + +int main(int argc, char** argv) +{ + int fd = -1; + FILE* fp; + struct ncr_master_key_st key; + int size; + + if (argc != 2) { + fprintf(stderr, "Usage: setkey [filename]\n"); + exit(1); + } + + memset(&key, 0, sizeof(key)); + fp = fopen(argv[1], "r"); + size = fread(key.key, 1, sizeof(key.key), fp); + if (size < 16) { + fprintf(stderr, "Illegal key!\n"); + exit(1); + } + fclose(fp); + key.key_size = size; + + /* Open the crypto device */ + fd = open("/dev/crypto", O_RDWR, 0); + if (fd < 0) { + perror("open(/dev/crypto)"); + return 1; + } + + /* encrypt */ + + if (ioctl(fd, NCRIO_MASTER_KEY_SET, &key)) { + fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__); + perror("ioctl(NCRIO_MASTER_KEY_SET)"); + return 1; + } + /* Close the original descriptor */ + if (close(fd)) { + perror("close(fd)"); + return 1; + } + + return 0; +} |