Print this page
first pass

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/crypto/io/blowfish.c
          +++ new/usr/src/uts/common/crypto/io/blowfish.c
↓ open down ↓ 232 lines elided ↑ open up ↑
 233  233  {
 234  234          return (mod_info(&modlinkage, modinfop));
 235  235  }
 236  236  
 237  237  /*
 238  238   * Initialize key schedules for blowfish
 239  239   */
 240  240  static int
 241  241  init_keysched(crypto_key_t *key, void *keysched)
 242  242  {
 243      -/* EXPORT DELETE START */
 244  243          /*
 245  244           * Only keys by value are supported by this module.
 246  245           */
 247  246          switch (key->ck_format) {
 248  247          case CRYPTO_KEY_RAW:
 249  248                  if (key->ck_length < BLOWFISH_MINBITS ||
 250  249                      key->ck_length > BLOWFISH_MAXBITS) {
 251  250                          return (CRYPTO_KEY_SIZE_RANGE);
 252  251                  }
 253  252                  break;
 254  253          default:
 255  254                  return (CRYPTO_KEY_TYPE_INCONSISTENT);
 256  255          }
 257  256  
 258  257          blowfish_init_keysched(key->ck_data, key->ck_length, keysched);
 259      -/* EXPORT DELETE END */
 260  258          return (CRYPTO_SUCCESS);
 261  259  }
 262  260  
 263  261  /*
 264  262   * KCF software provider control entry points.
 265  263   */
 266  264  /* ARGSUSED */
 267  265  static void
 268  266  blowfish_provider_status(crypto_provider_handle_t provider, uint_t *status)
 269  267  {
↓ open down ↓ 1 lines elided ↑ open up ↑
 271  269  }
 272  270  
 273  271  /*
 274  272   * KCF software provider encrypt entry points.
 275  273   */
 276  274  static int
 277  275  blowfish_common_init(crypto_ctx_t *ctx, crypto_mechanism_t *mechanism,
 278  276      crypto_key_t *key, crypto_spi_ctx_template_t template,
 279  277      crypto_req_handle_t req)
 280  278  {
 281      -
 282      -/* EXPORT DELETE START */
 283      -
 284  279          blowfish_ctx_t *blowfish_ctx;
 285  280          int rv;
 286  281          int kmflag;
 287  282  
 288  283          /*
 289  284           * Only keys by value are supported by this module.
 290  285           */
 291  286          if (key->ck_format != CRYPTO_KEY_RAW) {
 292  287                  return (CRYPTO_KEY_TYPE_INCONSISTENT);
 293  288          }
↓ open down ↓ 19 lines elided ↑ open up ↑
 313  308  
 314  309          rv = blowfish_common_init_ctx(blowfish_ctx, template, mechanism,
 315  310              key, kmflag);
 316  311          if (rv != CRYPTO_SUCCESS) {
 317  312                  crypto_free_mode_ctx(blowfish_ctx);
 318  313                  return (rv);
 319  314          }
 320  315  
 321  316          ctx->cc_provider_private = blowfish_ctx;
 322  317  
 323      -/* EXPORT DELETE END */
 324      -
 325  318          return (CRYPTO_SUCCESS);
 326  319  }
 327  320  
 328  321  static void
 329  322  blowfish_copy_block64(uint8_t *in, uint64_t *out)
 330  323  {
 331  324          if (IS_P2ALIGNED(in, sizeof (uint64_t))) {
 332  325                  /* LINTED: pointer alignment */
 333  326                  out[0] = *(uint64_t *)&in[0];
 334  327          } else {
↓ open down ↓ 3 lines elided ↑ open up ↑
 338  331          }
 339  332  }
 340  333  
 341  334  /* ARGSUSED */
 342  335  static int
 343  336  blowfish_encrypt(crypto_ctx_t *ctx, crypto_data_t *plaintext,
 344  337      crypto_data_t *ciphertext, crypto_req_handle_t req)
 345  338  {
 346  339          int ret;
 347  340  
 348      -/* EXPORT DELETE START */
 349      -
 350  341          blowfish_ctx_t *blowfish_ctx;
 351  342  
 352  343          /*
 353  344           * Plaintext must be a multiple of blowfish block size.
 354  345           * This test only works for non-padded mechanisms
 355  346           * when blocksize is 2^N.
 356  347           */
 357  348          if ((plaintext->cd_length & (BLOWFISH_BLOCK_LEN - 1)) != 0)
 358  349                  return (CRYPTO_DATA_LEN_RANGE);
 359  350  
↓ open down ↓ 11 lines elided ↑ open up ↑
 371  362                  return (CRYPTO_BUFFER_TOO_SMALL);
 372  363          }
 373  364  
 374  365          /*
 375  366           * Do an update on the specified input data.
 376  367           */
 377  368          ret = blowfish_encrypt_update(ctx, plaintext, ciphertext, req);
 378  369          ASSERT(blowfish_ctx->bc_remainder_len  == 0);
 379  370          (void) blowfish_free_context(ctx);
 380  371  
 381      -/* EXPORT DELETE END */
 382      -
 383  372          /* LINTED */
 384  373          return (ret);
 385  374  }
 386  375  
 387  376  /* ARGSUSED */
 388  377  static int
 389  378  blowfish_decrypt(crypto_ctx_t *ctx, crypto_data_t *ciphertext,
 390  379      crypto_data_t *plaintext, crypto_req_handle_t req)
 391  380  {
 392  381          int ret;
 393  382  
 394      -/* EXPORT DELETE START */
 395      -
 396  383          blowfish_ctx_t *blowfish_ctx;
 397  384  
 398  385          /*
 399  386           * Ciphertext must be a multiple of blowfish block size.
 400  387           * This test only works for non-padded mechanisms
 401  388           * when blocksize is 2^N.
 402  389           */
 403  390          if ((ciphertext->cd_length & (BLOWFISH_BLOCK_LEN - 1)) != 0)
 404  391                  return (CRYPTO_ENCRYPTED_DATA_LEN_RANGE);
 405  392  
↓ open down ↓ 11 lines elided ↑ open up ↑
 417  404                  return (CRYPTO_BUFFER_TOO_SMALL);
 418  405          }
 419  406  
 420  407          /*
 421  408           * Do an update on the specified input data.
 422  409           */
 423  410          ret = blowfish_decrypt_update(ctx, ciphertext, plaintext, req);
 424  411          ASSERT(blowfish_ctx->bc_remainder_len == 0);
 425  412          (void) blowfish_free_context(ctx);
 426  413  
 427      -/* EXPORT DELETE END */
 428      -
 429  414          /* LINTED */
 430  415          return (ret);
 431  416  }
 432  417  
 433  418  /* ARGSUSED */
 434  419  static int
 435  420  blowfish_encrypt_update(crypto_ctx_t *ctx, crypto_data_t *plaintext,
 436  421      crypto_data_t *ciphertext, crypto_req_handle_t req)
 437  422  {
 438  423          off_t saved_offset;
↓ open down ↓ 115 lines elided ↑ open up ↑
 554  539          plaintext->cd_offset = saved_offset;
 555  540  
 556  541          return (ret);
 557  542  }
 558  543  
 559  544  /* ARGSUSED */
 560  545  static int
 561  546  blowfish_encrypt_final(crypto_ctx_t *ctx, crypto_data_t *data,
 562  547      crypto_req_handle_t req)
 563  548  {
 564      -
 565      -/* EXPORT DELETE START */
 566      -
 567  549          blowfish_ctx_t *blowfish_ctx;
 568  550  
 569  551          ASSERT(ctx->cc_provider_private != NULL);
 570  552          blowfish_ctx = ctx->cc_provider_private;
 571  553  
 572  554          /*
 573  555           * There must be no unprocessed data.
 574  556           * This happens if the length of the last data is
 575  557           * not a multiple of the BLOWFISH block length.
 576  558           */
 577  559          if (blowfish_ctx->bc_remainder_len > 0)
 578  560                  return (CRYPTO_DATA_LEN_RANGE);
 579  561  
 580  562          (void) blowfish_free_context(ctx);
 581  563          data->cd_length = 0;
 582  564  
 583      -/* EXPORT DELETE END */
 584      -
 585  565          return (CRYPTO_SUCCESS);
 586  566  }
 587  567  
 588  568  /* ARGSUSED */
 589  569  static int
 590  570  blowfish_decrypt_final(crypto_ctx_t *ctx, crypto_data_t *data,
 591  571      crypto_req_handle_t req)
 592  572  {
 593      -
 594      -/* EXPORT DELETE START */
 595      -
 596  573          blowfish_ctx_t *blowfish_ctx;
 597  574  
 598  575          ASSERT(ctx->cc_provider_private != NULL);
 599  576          blowfish_ctx = ctx->cc_provider_private;
 600  577  
 601  578          /*
 602  579           * There must be no unprocessed ciphertext.
 603  580           * This happens if the length of the last ciphertext is
 604  581           * not a multiple of the BLOWFISH block length.
 605  582           */
 606  583          if (blowfish_ctx->bc_remainder_len > 0)
 607  584                  return (CRYPTO_ENCRYPTED_DATA_LEN_RANGE);
 608  585  
 609  586          (void) blowfish_free_context(ctx);
 610  587          data->cd_length = 0;
 611  588  
 612      -/* EXPORT DELETE END */
 613      -
 614  589          return (CRYPTO_SUCCESS);
 615  590  }
 616  591  
 617  592  /* ARGSUSED */
 618  593  static int
 619  594  blowfish_encrypt_atomic(crypto_provider_handle_t provider,
 620  595      crypto_session_id_t session_id, crypto_mechanism_t *mechanism,
 621  596      crypto_key_t *key, crypto_data_t *plaintext, crypto_data_t *ciphertext,
 622  597      crypto_spi_ctx_template_t template, crypto_req_handle_t req)
 623  598  {
↓ open down ↓ 166 lines elided ↑ open up ↑
 790  765  
 791  766  /*
 792  767   * KCF software provider context template entry points.
 793  768   */
 794  769  /* ARGSUSED */
 795  770  static int
 796  771  blowfish_create_ctx_template(crypto_provider_handle_t provider,
 797  772      crypto_mechanism_t *mechanism, crypto_key_t *key,
 798  773      crypto_spi_ctx_template_t *tmpl, size_t *tmpl_size, crypto_req_handle_t req)
 799  774  {
 800      -
 801      -/* EXPORT DELETE START */
 802      -
 803  775          void *keysched;
 804  776          size_t size;
 805  777          int rv;
 806  778  
 807  779          if (!BLOWFISH_VALID_MECH(mechanism))
 808  780                  return (CRYPTO_MECHANISM_INVALID);
 809  781  
 810  782          if ((keysched = blowfish_alloc_keysched(&size,
 811  783              crypto_kmflag(req))) == NULL) {
 812  784                  return (CRYPTO_HOST_MEMORY);
↓ open down ↓ 5 lines elided ↑ open up ↑
 818  790           */
 819  791          if ((rv = init_keysched(key, keysched)) != CRYPTO_SUCCESS) {
 820  792                  bzero(keysched, size);
 821  793                  kmem_free(keysched, size);
 822  794                  return (rv);
 823  795          }
 824  796  
 825  797          *tmpl = keysched;
 826  798          *tmpl_size = size;
 827  799  
 828      -/* EXPORT DELETE END */
 829      -
 830  800          return (CRYPTO_SUCCESS);
 831  801  }
 832  802  
 833  803  /* ARGSUSED */
 834  804  static int
 835  805  blowfish_free_context(crypto_ctx_t *ctx)
 836  806  {
 837  807          blowfish_ctx_t *blowfish_ctx = ctx->cc_provider_private;
 838  808  
 839  809          if (blowfish_ctx != NULL) {
↓ open down ↓ 12 lines elided ↑ open up ↑
 852  822  }
 853  823  
 854  824  /* ARGSUSED */
 855  825  static int
 856  826  blowfish_common_init_ctx(blowfish_ctx_t *blowfish_ctx,
 857  827      crypto_spi_ctx_template_t *template, crypto_mechanism_t *mechanism,
 858  828      crypto_key_t *key, int kmflag)
 859  829  {
 860  830          int rv = CRYPTO_SUCCESS;
 861  831  
 862      -/* EXPORT DELETE START */
 863      -
 864  832          void *keysched;
 865  833          size_t size;
 866  834  
 867  835          if (template == NULL) {
 868  836                  if ((keysched = blowfish_alloc_keysched(&size, kmflag)) == NULL)
 869  837                          return (CRYPTO_HOST_MEMORY);
 870  838                  /*
 871  839                   * Initialize key schedule.
 872  840                   * Key length is stored in the key.
 873  841                   */
↓ open down ↓ 17 lines elided ↑ open up ↑
 891  859                  blowfish_ctx->bc_flags |= ECB_MODE;
 892  860          }
 893  861  
 894  862          if (rv != CRYPTO_SUCCESS) {
 895  863                  if (blowfish_ctx->bc_flags & PROVIDER_OWNS_KEY_SCHEDULE) {
 896  864                          bzero(keysched, size);
 897  865                          kmem_free(keysched, size);
 898  866                  }
 899  867          }
 900  868  
 901      -/* EXPORT DELETE END */
 902      -
 903  869          return (rv);
 904  870  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX