Print this page
9697 Add digest tests to crypto test framework

Split Close
Expand all
Collapse all
          --- old/usr/src/test/crypto-tests/tests/common/testfuncs.c
          +++ new/usr/src/test/crypto-tests/tests/common/testfuncs.c
↓ open down ↓ 3 lines elided ↑ open up ↑
   4    4   * You may only use this file in accordance with the terms of version
   5    5   * 1.0 of the CDDL.
   6    6   *
   7    7   * A full copy of the text of the CDDL should have accompanied this
   8    8   * source.  A copy of the CDDL is also available via the Internet at
   9    9   * http://www.illumos.org/license/CDDL.
  10   10   */
  11   11  
  12   12  /*
  13   13   * Copyright 2016 Nexenta Systems, Inc.  All rights reserved.
       14 + * Copyright 2018, Joyent, Inc.
  14   15   */
  15   16  
  16   17  #define __EXTENSIONS__
  17   18  #include <strings.h>
  18   19  #include <stdlib.h>
  19   20  #include <stdio.h>
  20   21  #include "cryptotest.h"
  21   22  
  22   23  
  23   24  
  24   25  test_fg_t cryptotest_decr_fg = {test_decrypt_single, test_decrypt};
  25   26  test_fg_t cryptotest_encr_fg = {test_encrypt_single, test_encrypt};
  26   27  test_fg_t cryptotest_mac_fg = {test_mac_single, test_mac};
       28 +test_fg_t cryptotest_digest_fg = {test_digest_single, test_digest};
  27   29  
  28   30  /*
  29   31   * Utils
  30   32   */
  31   33  
  32   34  void
  33   35  printbuf(uint8_t *buf, char *name, size_t size)
  34   36  {
  35   37          size_t i;
  36   38  
↓ open down ↓ 221 lines elided ↑ open up ↑
 258  260  test_decrypt_single(cryptotest_t *args)
 259  261  {
 260  262          return (test_decrypt_common(args, B_TRUE));
 261  263  }
 262  264  
 263  265  
 264  266  int
 265  267  test_decrypt(cryptotest_t *args)
 266  268  {
 267  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));
 268  323  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX