Print this page
9697 Add digest tests to crypto test framework
   1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright 2016 Nexenta Systems, Inc.  All rights reserved.

  14  */
  15 
  16 #define __EXTENSIONS__
  17 #include <strings.h>
  18 #include <stdlib.h>
  19 #include <stdio.h>
  20 #include "cryptotest.h"
  21 
  22 
  23 
  24 test_fg_t cryptotest_decr_fg = {test_decrypt_single, test_decrypt};
  25 test_fg_t cryptotest_encr_fg = {test_encrypt_single, test_encrypt};
  26 test_fg_t cryptotest_mac_fg = {test_mac_single, test_mac};

  27 
  28 /*
  29  * Utils
  30  */
  31 
  32 void
  33 printbuf(uint8_t *buf, char *name, size_t size)
  34 {
  35         size_t i;
  36 
  37         flockfile(stderr);
  38         (void) fprintf(stderr, "%s%s", name, (size > 0) ? " " : "");
  39         for (i = 0; i < size; i++)
  40                 (void) fprintf(stderr, "%02x", buf[i]);
  41         (void) fputc('\n', stderr);
  42         funlockfile(stderr);
  43 }
  44 
  45 int
  46 bufcmp(uint8_t *auth, uint8_t *cmp, size_t size)


 248                         goto out;
 249 
 250         }
 251 
 252 out:
 253         (void) cryptotest_close(crypto_op);
 254         return (ret);
 255 }
 256 
 257 int
 258 test_decrypt_single(cryptotest_t *args)
 259 {
 260         return (test_decrypt_common(args, B_TRUE));
 261 }
 262 
 263 
 264 int
 265 test_decrypt(cryptotest_t *args)
 266 {
 267         return (test_decrypt_common(args, B_FALSE));





















































 268 }
   1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright 2016 Nexenta Systems, Inc.  All rights reserved.
  14  * Copyright 2018, Joyent, Inc.
  15  */
  16 
  17 #define __EXTENSIONS__
  18 #include <strings.h>
  19 #include <stdlib.h>
  20 #include <stdio.h>
  21 #include "cryptotest.h"
  22 
  23 
  24 
  25 test_fg_t cryptotest_decr_fg = {test_decrypt_single, test_decrypt};
  26 test_fg_t cryptotest_encr_fg = {test_encrypt_single, test_encrypt};
  27 test_fg_t cryptotest_mac_fg = {test_mac_single, test_mac};
  28 test_fg_t cryptotest_digest_fg = {test_digest_single, test_digest};
  29 
  30 /*
  31  * Utils
  32  */
  33 
  34 void
  35 printbuf(uint8_t *buf, char *name, size_t size)
  36 {
  37         size_t i;
  38 
  39         flockfile(stderr);
  40         (void) fprintf(stderr, "%s%s", name, (size > 0) ? " " : "");
  41         for (i = 0; i < size; i++)
  42                 (void) fprintf(stderr, "%02x", buf[i]);
  43         (void) fputc('\n', stderr);
  44         funlockfile(stderr);
  45 }
  46 
  47 int
  48 bufcmp(uint8_t *auth, uint8_t *cmp, size_t size)


 250                         goto out;
 251 
 252         }
 253 
 254 out:
 255         (void) cryptotest_close(crypto_op);
 256         return (ret);
 257 }
 258 
 259 int
 260 test_decrypt_single(cryptotest_t *args)
 261 {
 262         return (test_decrypt_common(args, B_TRUE));
 263 }
 264 
 265 
 266 int
 267 test_decrypt(cryptotest_t *args)
 268 {
 269         return (test_decrypt_common(args, B_FALSE));
 270 }
 271 
 272 static int
 273 test_digest_common(cryptotest_t *args, boolean_t AIO)
 274 {
 275         int ret, i;
 276         crypto_op_t *crypto_op;
 277 
 278         if ((crypto_op = cryptotest_init(args, CRYPTO_FG_DIGEST)) == NULL) {
 279                 (void) fprintf(stderr, "Error occured during initalization\n");
 280                 (void) cryptotest_close(NULL);
 281                 return (CTEST_INIT_FAILED);
 282         }
 283 
 284         if ((ret = get_mech_info(crypto_op)) != CRYPTO_SUCCESS)
 285                 goto out;
 286 
 287         if ((ret = get_hsession_by_mech(crypto_op)) != CRYPTO_SUCCESS)
 288                 goto out;
 289 
 290         if ((ret = digest_init(crypto_op)) != CRYPTO_SUCCESS)
 291                 goto out;
 292 
 293         if (AIO) {
 294                 if ((ret = digest_single(crypto_op)) != CRYPTO_SUCCESS)
 295                         goto out;
 296         } else {
 297                 for (i = 0; i < args->inlen; i += args->updatelen) {
 298 
 299                         if ((ret = digest_update(crypto_op, i)) !=
 300                             CRYPTO_SUCCESS)
 301                                 goto out;
 302                 }
 303 
 304                 if ((ret = digest_final(crypto_op)) != CRYPTO_SUCCESS)
 305                         goto out;
 306         }
 307 
 308 out:
 309         (void) cryptotest_close(crypto_op);
 310         return (ret);
 311 }
 312 
 313 int
 314 test_digest_single(cryptotest_t *args)
 315 {
 316         return (test_digest_common(args, B_TRUE));
 317 }
 318 
 319 int
 320 test_digest(cryptotest_t *args)
 321 {
 322         return (test_digest_common(args, B_FALSE));
 323 }