crypto.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _FS_CEPH_CRYPTO_H
  3. #define _FS_CEPH_CRYPTO_H
  4. #include <crypto/sha2.h>
  5. #include <linux/ceph/types.h>
  6. #include <linux/ceph/buffer.h>
  7. #define CEPH_MAX_KEY_LEN 32
  8. #define CEPH_MAX_CON_SECRET_LEN 64
  9. /*
  10. * cryptographic secret
  11. */
  12. struct ceph_crypto_key {
  13. int type;
  14. struct ceph_timespec created;
  15. int len;
  16. void *key;
  17. union {
  18. struct crypto_sync_skcipher *aes_tfm;
  19. struct {
  20. struct hmac_sha256_key hmac_key;
  21. const struct krb5_enctype *krb5_type;
  22. struct crypto_aead *krb5_tfms[3];
  23. };
  24. };
  25. };
  26. int ceph_crypto_key_prepare(struct ceph_crypto_key *key,
  27. const u32 *key_usages, int key_usage_cnt);
  28. int ceph_crypto_key_clone(struct ceph_crypto_key *dst,
  29. const struct ceph_crypto_key *src);
  30. int ceph_crypto_key_decode(struct ceph_crypto_key *key, void **p, void *end);
  31. int ceph_crypto_key_unarmor(struct ceph_crypto_key *key, const char *in);
  32. void ceph_crypto_key_destroy(struct ceph_crypto_key *key);
  33. /* crypto.c */
  34. int ceph_crypt(const struct ceph_crypto_key *key, int usage_slot, bool encrypt,
  35. void *buf, int buf_len, int in_len, int *pout_len);
  36. int ceph_crypt_data_offset(const struct ceph_crypto_key *key);
  37. int ceph_crypt_buflen(const struct ceph_crypto_key *key, int data_len);
  38. void ceph_hmac_sha256(const struct ceph_crypto_key *key, const void *buf,
  39. int buf_len, u8 hmac[SHA256_DIGEST_SIZE]);
  40. int ceph_crypto_init(void);
  41. void ceph_crypto_shutdown(void);
  42. /* armor.c */
  43. int ceph_armor(char *dst, const char *src, const char *end);
  44. int ceph_unarmor(char *dst, const char *src, const char *end);
  45. #endif