asymmetric-type.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* Asymmetric Public-key cryptography key type interface
  2. *
  3. * See Documentation/security/asymmetric-keys.txt
  4. *
  5. * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
  6. * Written by David Howells (dhowells@redhat.com)
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public Licence
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the Licence, or (at your option) any later version.
  12. */
  13. #ifndef _KEYS_ASYMMETRIC_TYPE_H
  14. #define _KEYS_ASYMMETRIC_TYPE_H
  15. #include <linux/key-type.h>
  16. extern struct key_type key_type_asymmetric;
  17. /*
  18. * The key payload is four words. The asymmetric-type key uses them as
  19. * follows:
  20. */
  21. enum asymmetric_payload_bits {
  22. asym_crypto,
  23. asym_subtype,
  24. asym_key_ids,
  25. };
  26. /*
  27. * Identifiers for an asymmetric key ID. We have three ways of looking up a
  28. * key derived from an X.509 certificate:
  29. *
  30. * (1) Serial Number & Issuer. Non-optional. This is the only valid way to
  31. * map a PKCS#7 signature to an X.509 certificate.
  32. *
  33. * (2) Issuer & Subject Unique IDs. Optional. These were the original way to
  34. * match X.509 certificates, but have fallen into disuse in favour of (3).
  35. *
  36. * (3) Auth & Subject Key Identifiers. Optional. SKIDs are only provided on
  37. * CA keys that are intended to sign other keys, so don't appear in end
  38. * user certificates unless forced.
  39. *
  40. * We could also support an PGP key identifier, which is just a SHA1 sum of the
  41. * public key and certain parameters, but since we don't support PGP keys at
  42. * the moment, we shall ignore those.
  43. *
  44. * What we actually do is provide a place where binary identifiers can be
  45. * stashed and then compare against them when checking for an id match.
  46. */
  47. struct asymmetric_key_id {
  48. unsigned short len;
  49. unsigned char data[];
  50. };
  51. struct asymmetric_key_ids {
  52. void *id[2];
  53. };
  54. extern bool asymmetric_key_id_same(const struct asymmetric_key_id *kid1,
  55. const struct asymmetric_key_id *kid2);
  56. extern bool asymmetric_key_id_partial(const struct asymmetric_key_id *kid1,
  57. const struct asymmetric_key_id *kid2);
  58. extern struct asymmetric_key_id *asymmetric_key_generate_id(const void *val_1,
  59. size_t len_1,
  60. const void *val_2,
  61. size_t len_2);
  62. static inline
  63. const struct asymmetric_key_ids *asymmetric_key_ids(const struct key *key)
  64. {
  65. return key->payload.data[asym_key_ids];
  66. }
  67. /*
  68. * The payload is at the discretion of the subtype.
  69. */
  70. #endif /* _KEYS_ASYMMETRIC_TYPE_H */