EVP_KDF-KRB5KDF.pod 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. =pod
  2. =head1 NAME
  3. EVP_KDF-KRB5KDF - The RFC3961 Krb5 KDF EVP_KDF implementation
  4. =head1 DESCRIPTION
  5. Support for computing the B<KRB5KDF> KDF through the B<EVP_KDF> API.
  6. The EVP_KDF-KRB5KDF algorithm implements the key derivation function defined
  7. in RFC 3961, section 5.1 and is used by Krb5 to derive session keys.
  8. Three inputs are required to perform key derivation: a cipher, (for example
  9. AES-128-CBC), the initial key, and a constant.
  10. =head2 Identity
  11. "KRB5KDF" is the name for this implementation;
  12. it can be used with the EVP_KDF_fetch() function.
  13. =head2 Supported parameters
  14. The supported parameters are:
  15. =over 4
  16. =item "properties" (B<OSSL_KDF_PARAM_PROPERTIES>) <UTF8 string>
  17. =item "cipher" (B<OSSL_KDF_PARAM_CIPHER>) <UTF8 string>
  18. =item "key" (B<OSSL_KDF_PARAM_KEY>) <octet string>
  19. These parameters work as described in L<EVP_KDF(3)/PARAMETERS>.
  20. =item "constant" (B<OSSL_KDF_PARAM_CONSTANT>) <octet string>
  21. This parameter sets the constant value for the KDF.
  22. If a value is already set, the contents are replaced.
  23. =back
  24. =head1 NOTES
  25. A context for KRB5KDF can be obtained by calling:
  26. EVP_KDF *kdf = EVP_KDF_fetch(NULL, "KRB5KDF", NULL);
  27. EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
  28. The output length of the KRB5KDF derivation is specified via the I<keylen>
  29. parameter to the L<EVP_KDF_derive(3)> function, and MUST match the key
  30. length for the chosen cipher or an error is returned. Moreover, the
  31. constant's length must not exceed the block size of the cipher.
  32. Since the KRB5KDF output length depends on the chosen cipher, calling
  33. L<EVP_KDF_CTX_get_kdf_size(3)> to obtain the requisite length returns the correct length
  34. only after the cipher is set. Prior to that B<EVP_MAX_KEY_LENGTH> is returned.
  35. The caller must allocate a buffer of the correct length for the chosen
  36. cipher, and pass that buffer to the L<EVP_KDF_derive(3)> function along
  37. with that length.
  38. =head1 EXAMPLES
  39. This example derives a key using the AES-128-CBC cipher:
  40. EVP_KDF *kdf;
  41. EVP_KDF_CTX *kctx;
  42. unsigned char key[16] = "01234...";
  43. unsigned char constant[] = "I'm a constant";
  44. unsigned char out[16];
  45. size_t outlen = sizeof(out);
  46. OSSL_PARAM params[4], *p = params;
  47. kdf = EVP_KDF_fetch(NULL, "KRB5KDF", NULL);
  48. kctx = EVP_KDF_CTX_new(kdf);
  49. EVP_KDF_free(kdf);
  50. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_CIPHER,
  51. SN_aes_128_cbc,
  52. strlen(SN_aes_128_cbc));
  53. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
  54. key, (size_t)16);
  55. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_CONSTANT,
  56. constant, strlen(constant));
  57. *p = OSSL_PARAM_construct_end();
  58. if (EVP_KDF_derive(kctx, out, outlen, params) <= 0)
  59. /* Error */
  60. EVP_KDF_CTX_free(kctx);
  61. =head1 CONFORMING TO
  62. RFC 3961
  63. =head1 SEE ALSO
  64. L<EVP_KDF(3)>,
  65. L<EVP_KDF_CTX_free(3)>,
  66. L<EVP_KDF_CTX_get_kdf_size(3)>,
  67. L<EVP_KDF_derive(3)>,
  68. L<EVP_KDF(3)/PARAMETERS>
  69. =head1 HISTORY
  70. This functionality was added to OpenSSL 3.0.
  71. =head1 COPYRIGHT
  72. Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
  73. Licensed under the Apache License 2.0 (the "License"). You may not use
  74. this file except in compliance with the License. You can obtain a copy
  75. in the file LICENSE in the source distribution or at
  76. L<https://www.openssl.org/source/license.html>.
  77. =cut