diff options
author | Miloslav Trmač <mitr@redhat.com> | 2010-08-25 00:28:25 +0200 |
---|---|---|
committer | Miloslav Trmač <mitr@redhat.com> | 2010-08-25 00:28:25 +0200 |
commit | d9c91873ac6dee10aeb7e165dee3aefc5f79bba8 (patch) | |
tree | 55cd455c5b6b8cc3a532a36bcd21b135425afda5 /examples/ncr.c | |
parent | cc60983067194a6e7bdc12c7771aeaff6762a253 (diff) | |
parent | 1ba66cab0563708d551e3462c249f1da21695882 (diff) | |
download | cryptodev-linux-d9c91873ac6dee10aeb7e165dee3aefc5f79bba8.tar.gz cryptodev-linux-d9c91873ac6dee10aeb7e165dee3aefc5f79bba8.tar.xz cryptodev-linux-d9c91873ac6dee10aeb7e165dee3aefc5f79bba8.zip |
Merge branch 'bugfixes' into nlattr
Conflicts:
cryptodev_main.c
examples/ncr.c
examples/pk.c
ncr-int.h
ncr-key-wrap.c
ncr-key.c
ncr.c
ncr.h
Diffstat (limited to 'examples/ncr.c')
-rw-r--r-- | examples/ncr.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/examples/ncr.c b/examples/ncr.c index 343208e..9112873 100644 --- a/examples/ncr.c +++ b/examples/ncr.c @@ -353,7 +353,7 @@ test_ncr_key(int cfd) static int test_ncr_wrap_key(int cfd) { - int i; + int i, ret; ncr_key_t key, key2; struct __attribute__((packed)) { struct ncr_key_import f; @@ -377,6 +377,10 @@ test_ncr_wrap_key(int cfd) char wrap_algo[sizeof(NCR_WALG_AES_RFC3394)] ALIGN_NL; struct nlattr algo_head ALIGN_NL; char algo[sizeof(ALG_AES_CBC)] ALIGN_NL; + struct nlattr type_head ALIGN_NL; + uint32_t type ALIGN_NL; + struct nlattr flags_head ALIGN_NL; + uint32_t flags ALIGN_NL; } kunwrap; uint8_t data[WRAPPED_KEY_DATA_SIZE]; int data_size; @@ -415,12 +419,18 @@ test_ncr_wrap_key(int cfd) kimport.flags_head.nla_type = NCR_ATTR_KEY_FLAGS; kimport.flags = NCR_KEY_FLAG_EXPORTABLE|NCR_KEY_FLAG_WRAPPING; - if (ioctl(cfd, NCRIO_KEY_IMPORT, &kimport)) { + ret = ioctl(cfd, NCRIO_KEY_IMPORT, &kimport); + if (geteuid() == 0 && ret) { fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__); perror("ioctl(NCRIO_KEY_IMPORT)"); return 1; } + if (geteuid() != 0) { + /* cannot test further */ + fprintf(stdout, "\t(Wrapping test not completed. Run as root)\n"); + return 0; + } /* convert it to key */ key2 = ioctl(cfd, NCRIO_KEY_INIT); @@ -467,17 +477,11 @@ test_ncr_wrap_key(int cfd) strcpy(kwrap.algo, NCR_WALG_AES_RFC3394); data_size = ioctl(cfd, NCRIO_KEY_WRAP, &kwrap); - if (geteuid() == 0 && data_size < 0) { + if (data_size < 0) { fprintf(stderr, "Error: %s:%d\n", __func__, __LINE__); perror("ioctl(NCRIO_KEY_WRAP)"); return 1; } - - if (geteuid() != 0) { - /* cannot test further */ - fprintf(stdout, "\t(Wrapping test not completed. Run as root)\n"); - return 0; - } if (data_size != 24 || memcmp(data, "\x1F\xA6\x8B\x0A\x81\x12\xB4\x47\xAE\xF3\x4B\xD8\xFB\x5A\x7B\x82\x9D\x3E\x86\x23\x71\xD2\xCF\xE5", 24) != 0) { @@ -517,6 +521,12 @@ test_ncr_wrap_key(int cfd) kunwrap.algo_head.nla_len = NLA_HDRLEN + sizeof(kunwrap.algo); kunwrap.algo_head.nla_type = NCR_ATTR_ALGORITHM; strcpy(kunwrap.algo, ALG_AES_CBC); + kunwrap.type_head.nla_len = NLA_HDRLEN + sizeof(kunwrap.type); + kunwrap.type_head.nla_type = NCR_ATTR_KEY_TYPE; + kunwrap.type = NCR_KEY_TYPE_SECRET; + kunwrap.flags_head.nla_len = NLA_HDRLEN + sizeof(kunwrap.flags); + kunwrap.flags_head.nla_type = NCR_ATTR_KEY_FLAGS; + kunwrap.flags = NCR_KEY_FLAG_EXPORTABLE|NCR_KEY_FLAG_WRAPPABLE; if (ioctl(cfd, NCRIO_KEY_UNWRAP, &kunwrap)) { perror("ioctl(NCRIO_KEY_UNWRAP)"); |