Skip to content

Cryptographic action

Name

Cryptographic action

Summary

This pattern encapsulates the common considerations one should take into account when integrating cryptographic primitives into a system. Consequently, this pattern by itself does not address specific security problems in this catalogue but acts as a building for a range of other patterns that use cryptography as part of their proposed solution.

Parent

  • None

Problem

This pattern does not directly address a security problem of this catalogue, but encapsulates common issues when applying solutions involving cryptography.

Solution

This pattern encapsulates the commonalities to be considered when a system relies on some cryptographic library to perform cryptographic actions such as encrypting or digitally signing data elements. The implementations address the considerations specific to different types of actions.

Info

This pattern only addresses the requesting and performing cryptographic actions. A crucial part of correctly applying solutions involving cryptography is managing the used cryptographic keys which is addressed in the Cryptographic key management pattern.

Roles

  • Entity (: Entity) wants to perform one or more cryptographic actions
  • Cryptographer (: Cryptographic primitive) a cryptographic library that provides one or more cryptographic actions

Actions

  • crypto_action (: Action) request to perform a cryptographic action, e.g. encryption or generating a digital signature, on a given input using the identified key. The exact action is refined in this pattern's implementations.

Data elements

  • input (: Data) the plaintext input on which the cryptographic action should be performed
  • output (: Data) the result of performing the requested cryptographic action, e.g. a ciphertext or digital signature
  • keyInfo (: Data) information on the cryptographic key to be used when performing a cryptographic action. This can, for example, be an identifier so that the Cryptographer knows which key to use or the cryptographic key itself. The exact information depends on the chosen key management method (cf. Cryptographic key management).
    • Tags: Untampered[, Secret]
  • config (: Data) the configuration for the Cryptographer containing, for example, the desired cipher (mode) (optional)

Behaviour

  1. The Entity requests the Cryptographer to perform a certain cryptographic action, e.g. encrypt or generate a digital signature, on a given input using the identified key. If necessary, the Entity also provides a configuration.
  2. The Cryptographer performs the requested action and replies the result to the Entity.

Entity requesting a cryptographic action from a cryptographer

Role considerations

Reuse existing libraries (Cryptographer)

One should always use existing, well-known libraries when integrating cryptography into a system.1 2 One should never attempt to define new, custom libraries, either defining new cryptographic ciphers or implementing existing ones.

Before selecting and integrating a specific library into one's system it is advised to consult the documentation of the candidate libraries. More specifically, one should verify whether the library makes any assumptions or has any dependencies that cannot be met by the system under design. Libraries that are no longer actively maintained or deviate from advised best practices should be approached with caution.

Use keys for a single purpose (Entity)

A cryptographic key should never be used for multiple purposes, e.g. using the same key encrypting as well as signing data.3 4 Doing so may negatively impact the security properties of the cryptographic operations in which the key is used and increases the possible damage in case the key is compromised.

Design for change (Entity, Cryptographer)

Over time the discovery of new vulnerabilities in cryptographic ciphers (or their implementations), as well as gains in processing power will likely make the selected cipher or library no longer suitable at some point in the future. In that case it should be possible to change its configuration, e.g. use longer cryptographic keys, or change to a new cipher or library altogether. Therefore, software designers are advised to design their software in such a way that allows such transitions to be as easy as possible.1 2

One possible way to design for these kind of changes is to provide an API abstraction around the integrated cryptography library.1 Such an abstraction layer can provide a stable cryptography API to the remainder of the system, i.e. Entity, while allowing the underlying library to evolve over time, e.g. updating to the library or replacing it by a different one. Furthermore, this API can enforce secure configuration defaults, e.g. cipher modes and key lengths, such that designers are not required to make such decisions each time.

Cryptographer configuration

Depending on the exact cryptographic action and chosen library, different options may be configured for the cryptographers, e.g. desired cipher (mode) and key length. It is strongly advised to consult the documentation of your selected library for specific guidelines and stick to the defaults where appropriate. The implementations of this pattern provide considerations to take into account for specific cryptographic actions.

Data considerations

config

In case the Entity provides a desired configuration to the Cryptographer it should be possible to detect any authorised changes to it. An attacker might, for example, tamper with an encryption configuration to use insecure, deprecated ciphers so that the encryption can easily be broken afterwards. The configuration should thus be protected against undetected tampering while transmitted between Entity and Cryptographer as well as when it is stored by the Entity.

Note, that in some cases the configuration provided by the Entity respectively might provide an attacker with relevant information concerning the encryption key(s) that will be used. In such a case, additional measures to keep the configuration confidential can be warranted.

keyInfo

See Cryptographic key management.keyInfo

Implementations

References

Pointers to cryptographic libraries can be found in the implementing patterns and in the related pattern addressing Cryptographic key management as well as its implementations.


  1. I. Arce et al., ‘Avoiding the Top 10 Software Security Design Flaws’, IEEE, 2014. [Online]. Available: https://cybersecurity.ieee.org/blog/2015/11/13/avoiding-the-top-10-security-flaws/ ↩↩↩

  2. Bundesamt für Sicherheit in der Informationstechnik, ‘Cryptographic Mechanisms: Recommendations and Key Lengths’, BSI TR-02102-1, Mar. 2020. [Online]. Available: https://www.bsi.bund.de/SharedDocs/Downloads/EN/BSI/Publications/TechGuidelines/TG02102/BSI-TR-02102-1.html ↩↩

  3. E. Barker, ‘Recommendation for Key Management: Part 1 – General’, NIST, 800–57 Part 1, May 2020. [Online]. Available: https://doi.org/10.6028/NIST.SP.800-57pt1r5 ↩

  4. P. C. van Oorschot, Computer Security and the Internet - Tools and Jewels. 2020. [Online]. Available: https://doi.org/10.1007/978-3-030-33649-3 ↩


Last update: February 24, 2022