asymmetric-type.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #include <linux/verification.h>
  17. extern struct key_type key_type_asymmetric;
  18. /*
  19. * The key payload is four words. The asymmetric-type key uses them as
  20. * follows:
  21. */
  22. enum asymmetric_payload_bits {
  23. asym_crypto, /* The data representing the key */
  24. asym_subtype, /* Pointer to an asymmetric_key_subtype struct */
  25. asym_key_ids, /* Pointer to an asymmetric_key_ids struct */
  26. asym_auth /* The key's authorisation (signature, parent key ID) */
  27. };
  28. /*
  29. * Identifiers for an asymmetric key ID. We have three ways of looking up a
  30. * key derived from an X.509 certificate:
  31. *
  32. * (1) Serial Number & Issuer. Non-optional. This is the only valid way to
  33. * map a PKCS#7 signature to an X.509 certificate.
  34. *
  35. * (2) Issuer & Subject Unique IDs. Optional. These were the original way to
  36. * match X.509 certificates, but have fallen into disuse in favour of (3).
  37. *
  38. * (3) Auth & Subject Key Identifiers. Optional. SKIDs are only provided on
  39. * CA keys that are intended to sign other keys, so don't appear in end
  40. * user certificates unless forced.
  41. *
  42. * We could also support an PGP key identifier, which is just a SHA1 sum of the
  43. * public key and certain parameters, but since we don't support PGP keys at
  44. * the moment, we shall ignore those.
  45. *
  46. * What we actually do is provide a place where binary identifiers can be
  47. * stashed and then compare against them when checking for an id match.
  48. */
  49. struct asymmetric_key_id {
  50. unsigned short len;
  51. unsigned char data[];
  52. };
  53. struct asymmetric_key_ids {
  54. void *id[2];
  55. };
  56. extern bool asymmetric_key_id_same(const struct asymmetric_key_id *kid1,
  57. const struct asymmetric_key_id *kid2);
  58. extern bool asymmetric_key_id_partial(const struct asymmetric_key_id *kid1,
  59. const struct asymmetric_key_id *kid2);
  60. extern struct asymmetric_key_id *asymmetric_key_generate_id(const void *val_1,
  61. size_t len_1,
  62. const void *val_2,
  63. size_t len_2);
  64. static inline
  65. const struct asymmetric_key_ids *asymmetric_key_ids(const struct key *key)
  66. {
  67. return key->payload.data[asym_key_ids];
  68. }
  69. extern struct key *find_asymmetric_key(struct key *keyring,
  70. const struct asymmetric_key_id *id_0,
  71. const struct asymmetric_key_id *id_1,
  72. bool partial);
  73. /*
  74. * The payload is at the discretion of the subtype.
  75. */
  76. #endif /* _KEYS_ASYMMETRIC_TYPE_H */