Gilles Peskine | 6c723a2 | 2020-04-17 16:57:52 +0200 | [diff] [blame] | 1 | |
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
| 3 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 4 | |
| 5 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 6 | <head> |
| 7 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
Gilles Peskine | c2db5f0 | 2021-01-18 20:36:53 +0100 | [diff] [blame^] | 8 | <title>Example macro implementations — PSA Crypto API 1.0.1 documentation</title> |
Gilles Peskine | 6c723a2 | 2020-04-17 16:57:52 +0200 | [diff] [blame] | 9 | <link rel="stylesheet" href="../_static/alabaster.css" type="text/css" /> |
| 10 | <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> |
| 11 | <script type="text/javascript"> |
| 12 | var DOCUMENTATION_OPTIONS = { |
| 13 | URL_ROOT: '../', |
Gilles Peskine | c2db5f0 | 2021-01-18 20:36:53 +0100 | [diff] [blame^] | 14 | VERSION: '1.0.1', |
Gilles Peskine | 6c723a2 | 2020-04-17 16:57:52 +0200 | [diff] [blame] | 15 | COLLAPSE_INDEX: false, |
| 16 | FILE_SUFFIX: '.html', |
Gilles Peskine | c2db5f0 | 2021-01-18 20:36:53 +0100 | [diff] [blame^] | 17 | HAS_SOURCE: false, |
Gilles Peskine | 6c723a2 | 2020-04-17 16:57:52 +0200 | [diff] [blame] | 18 | SOURCELINK_SUFFIX: '.txt' |
| 19 | }; |
| 20 | </script> |
| 21 | <script type="text/javascript" src="../_static/jquery.js"></script> |
| 22 | <script type="text/javascript" src="../_static/underscore.js"></script> |
| 23 | <script type="text/javascript" src="../_static/doctools.js"></script> |
Gilles Peskine | c2db5f0 | 2021-01-18 20:36:53 +0100 | [diff] [blame^] | 24 | <link rel="author" title="About these documents" href="../about.html" /> |
Gilles Peskine | 6c723a2 | 2020-04-17 16:57:52 +0200 | [diff] [blame] | 25 | <link rel="index" title="Index" href="../genindex.html" /> |
| 26 | <link rel="search" title="Search" href="../search.html" /> |
| 27 | <link rel="next" title="Changes to the API" href="history.html" /> |
| 28 | <link rel="prev" title="Example header file" href="example_header.html" /> |
| 29 | |
| 30 | <link rel="stylesheet" href="../_static/custom.css" type="text/css" /> |
| 31 | |
| 32 | <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" /> |
| 33 | |
| 34 | </head> |
| 35 | <body> |
| 36 | |
| 37 | |
| 38 | <div class="document"> |
| 39 | <div class="documentwrapper"> |
| 40 | <div class="bodywrapper"> |
| 41 | <div class="body" role="main"> |
| 42 | |
| 43 | <div class="section" id="example-macro-implementations"> |
| 44 | <span id="appendix-specdef-values"></span><h1>Example macro implementations</h1> |
| 45 | <p>This appendix provides example implementations of the function-like macros that have specification-defined values.</p> |
| 46 | <div class="admonition note"> |
| 47 | <p class="first admonition-title">Note</p> |
| 48 | <p class="last">In a future version of this specification, these example implementations will be replaced with a pseudo-code representation of the macro’s computation in the macro description.</p> |
| 49 | </div> |
| 50 | <p>The examples here provide correct results for the valid inputs defined by each API, for an implementation that supports all of the defined algorithms and key types. An implementation can provide alternative definitions of these macros:</p> |
| 51 | <ul class="simple"> |
| 52 | <li>If the implementation does not support all of the algorithms or key types, it can provide a simpler definition of applicable macros.</li> |
| 53 | <li>If the implementation provides vendor-specific algorithms or key types, it needs to extend the definitions of applicable macros.</li> |
| 54 | </ul> |
| 55 | <div class="section" id="algorithm-macros"> |
| 56 | <h2>Algorithm macros</h2> |
Gilles Peskine | c2db5f0 | 2021-01-18 20:36:53 +0100 | [diff] [blame^] | 57 | <pre class="literal-block"> |
| 58 | #define <a class="reference internal" href="../api/ops/aead.html#c.PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG" title="PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG">PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG</a>(aead_alg) \ |
| 59 | ((((aead_alg) & ~0x003f0000) == 0x05400100) ? <a class="reference internal" href="../api/ops/aead.html#c.PSA_ALG_CCM" title="PSA_ALG_CCM">PSA_ALG_CCM</a> : \ |
| 60 | (((aead_alg) & ~0x003f0000) == 0x05400200) ? <a class="reference internal" href="../api/ops/aead.html#c.PSA_ALG_GCM" title="PSA_ALG_GCM">PSA_ALG_GCM</a> : \ |
| 61 | (((aead_alg) & ~0x003f0000) == 0x05000500) ? <a class="reference internal" href="../api/ops/aead.html#c.PSA_ALG_CHACHA20_POLY1305" title="PSA_ALG_CHACHA20_POLY1305">PSA_ALG_CHACHA20_POLY1305</a> : \ |
| 62 | <a class="reference internal" href="../api/ops/algorithms.html#c.PSA_ALG_NONE" title="PSA_ALG_NONE">PSA_ALG_NONE</a>) |
| 63 | |
| 64 | #define <a class="reference internal" href="../api/ops/aead.html#c.PSA_ALG_AEAD_WITH_SHORTENED_TAG" title="PSA_ALG_AEAD_WITH_SHORTENED_TAG">PSA_ALG_AEAD_WITH_SHORTENED_TAG</a>(aead_alg, tag_length) \ |
| 65 | ((<a class="reference internal" href="../api/ops/algorithms.html#c.psa_algorithm_t" title="psa_algorithm_t">psa_algorithm_t</a>) (((aead_alg) & ~0x003f0000) | (((tag_length) & 0x3f) << 16))) |
| 66 | |
| 67 | #define <a class="reference internal" href="../api/ops/sign.html#c.PSA_ALG_DETERMINISTIC_ECDSA" title="PSA_ALG_DETERMINISTIC_ECDSA">PSA_ALG_DETERMINISTIC_ECDSA</a>(hash_alg) \ |
| 68 | ((<a class="reference internal" href="../api/ops/algorithms.html#c.psa_algorithm_t" title="psa_algorithm_t">psa_algorithm_t</a>) (0x06000700 | ((hash_alg) & 0x000000ff))) |
| 69 | |
| 70 | #define <a class="reference internal" href="../api/ops/sign.html#c.PSA_ALG_ECDSA" title="PSA_ALG_ECDSA">PSA_ALG_ECDSA</a>(hash_alg) \ |
| 71 | ((<a class="reference internal" href="../api/ops/algorithms.html#c.psa_algorithm_t" title="psa_algorithm_t">psa_algorithm_t</a>) (0x06000600 | ((hash_alg) & 0x000000ff))) |
| 72 | |
| 73 | #define <a class="reference internal" href="../api/ops/macs.html#c.PSA_ALG_FULL_LENGTH_MAC" title="PSA_ALG_FULL_LENGTH_MAC">PSA_ALG_FULL_LENGTH_MAC</a>(mac_alg) \ |
| 74 | ((<a class="reference internal" href="../api/ops/algorithms.html#c.psa_algorithm_t" title="psa_algorithm_t">psa_algorithm_t</a>) ((mac_alg) & ~0x003f0000)) |
| 75 | |
| 76 | #define <a class="reference internal" href="../api/ops/algorithms.html#c.PSA_ALG_GET_HASH" title="PSA_ALG_GET_HASH">PSA_ALG_GET_HASH</a>(alg) \ |
| 77 | (((alg) & 0x000000ff) == 0 ? <a class="reference internal" href="../api/ops/algorithms.html#c.PSA_ALG_NONE" title="PSA_ALG_NONE">PSA_ALG_NONE</a> : 0x02000000 | ((alg) & 0x000000ff)) |
| 78 | |
| 79 | #define <a class="reference internal" href="../api/ops/kdf.html#c.PSA_ALG_HKDF" title="PSA_ALG_HKDF">PSA_ALG_HKDF</a>(hash_alg) \ |
| 80 | ((<a class="reference internal" href="../api/ops/algorithms.html#c.psa_algorithm_t" title="psa_algorithm_t">psa_algorithm_t</a>) (0x08000100 | ((hash_alg) & 0x000000ff))) |
| 81 | |
| 82 | #define <a class="reference internal" href="../api/ops/macs.html#c.PSA_ALG_HMAC" title="PSA_ALG_HMAC">PSA_ALG_HMAC</a>(hash_alg) \ |
| 83 | ((<a class="reference internal" href="../api/ops/algorithms.html#c.psa_algorithm_t" title="psa_algorithm_t">psa_algorithm_t</a>) (0x03800000 | ((hash_alg) & 0x000000ff))) |
| 84 | |
| 85 | #define <a class="reference internal" href="../api/ops/algorithms.html#c.PSA_ALG_IS_AEAD" title="PSA_ALG_IS_AEAD">PSA_ALG_IS_AEAD</a>(alg) \ |
| 86 | (((alg) & 0x7f000000) == 0x05000000) |
| 87 | |
| 88 | #define <a class="reference internal" href="../api/ops/aead.html#c.PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER" title="PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER">PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER</a>(alg) \ |
| 89 | (((alg) & 0x7f400000) == 0x05400000) |
| 90 | |
| 91 | #define <a class="reference internal" href="../api/ops/algorithms.html#c.PSA_ALG_IS_ASYMMETRIC_ENCRYPTION" title="PSA_ALG_IS_ASYMMETRIC_ENCRYPTION">PSA_ALG_IS_ASYMMETRIC_ENCRYPTION</a>(alg) \ |
| 92 | (((alg) & 0x7f000000) == 0x07000000) |
| 93 | |
| 94 | #define <a class="reference internal" href="../api/ops/macs.html#c.PSA_ALG_IS_BLOCK_CIPHER_MAC" title="PSA_ALG_IS_BLOCK_CIPHER_MAC">PSA_ALG_IS_BLOCK_CIPHER_MAC</a>(alg) \ |
| 95 | (((alg) & 0x7fc00000) == 0x03c00000) |
| 96 | |
| 97 | #define <a class="reference internal" href="../api/ops/algorithms.html#c.PSA_ALG_IS_CIPHER" title="PSA_ALG_IS_CIPHER">PSA_ALG_IS_CIPHER</a>(alg) \ |
| 98 | (((alg) & 0x7f000000) == 0x03000000) |
| 99 | |
| 100 | #define <a class="reference internal" href="../api/ops/sign.html#c.PSA_ALG_IS_DETERMINISTIC_ECDSA" title="PSA_ALG_IS_DETERMINISTIC_ECDSA">PSA_ALG_IS_DETERMINISTIC_ECDSA</a>(alg) \ |
| 101 | (((alg) & ~0x000000ff) == 0x06000700) |
| 102 | |
| 103 | #define <a class="reference internal" href="../api/ops/ka.html#c.PSA_ALG_IS_ECDH" title="PSA_ALG_IS_ECDH">PSA_ALG_IS_ECDH</a>(alg) \ |
| 104 | (((alg) & 0x7fff0000) == 0x09020000) |
| 105 | |
| 106 | #define <a class="reference internal" href="../api/ops/sign.html#c.PSA_ALG_IS_ECDSA" title="PSA_ALG_IS_ECDSA">PSA_ALG_IS_ECDSA</a>(alg) \ |
| 107 | (((alg) & ~0x000001ff) == 0x06000600) |
| 108 | |
| 109 | #define <a class="reference internal" href="../api/ops/ka.html#c.PSA_ALG_IS_FFDH" title="PSA_ALG_IS_FFDH">PSA_ALG_IS_FFDH</a>(alg) \ |
| 110 | (((alg) & 0x7fff0000) == 0x09010000) |
| 111 | |
| 112 | #define <a class="reference internal" href="../api/ops/algorithms.html#c.PSA_ALG_IS_HASH" title="PSA_ALG_IS_HASH">PSA_ALG_IS_HASH</a>(alg) \ |
| 113 | (((alg) & 0x7f000000) == 0x02000000) |
| 114 | |
| 115 | #define <a class="reference internal" href="../api/ops/sign.html#c.PSA_ALG_IS_HASH_AND_SIGN" title="PSA_ALG_IS_HASH_AND_SIGN">PSA_ALG_IS_HASH_AND_SIGN</a>(alg) \ |
| 116 | (<a class="reference internal" href="../api/ops/sign.html#c.PSA_ALG_IS_RSA_PSS" title="PSA_ALG_IS_RSA_PSS">PSA_ALG_IS_RSA_PSS</a>(alg) || <a class="reference internal" href="../api/ops/sign.html#c.PSA_ALG_IS_RSA_PKCS1V15_SIGN" title="PSA_ALG_IS_RSA_PKCS1V15_SIGN">PSA_ALG_IS_RSA_PKCS1V15_SIGN</a>(alg) || <a class="reference internal" href="../api/ops/sign.html#c.PSA_ALG_IS_ECDSA" title="PSA_ALG_IS_ECDSA">PSA_ALG_IS_ECDSA</a>(alg)) |
| 117 | |
| 118 | #define <a class="reference internal" href="../api/ops/kdf.html#c.PSA_ALG_IS_HKDF" title="PSA_ALG_IS_HKDF">PSA_ALG_IS_HKDF</a>(alg) \ |
| 119 | (((alg) & ~0x000000ff) == 0x08000100) |
| 120 | |
| 121 | #define <a class="reference internal" href="../api/ops/macs.html#c.PSA_ALG_IS_HMAC" title="PSA_ALG_IS_HMAC">PSA_ALG_IS_HMAC</a>(alg) \ |
| 122 | (((alg) & 0x7fc0ff00) == 0x03800000) |
| 123 | |
| 124 | #define <a class="reference internal" href="../api/ops/algorithms.html#c.PSA_ALG_IS_KEY_AGREEMENT" title="PSA_ALG_IS_KEY_AGREEMENT">PSA_ALG_IS_KEY_AGREEMENT</a>(alg) \ |
| 125 | (((alg) & 0x7f000000) == 0x09000000) |
| 126 | |
| 127 | #define <a class="reference internal" href="../api/ops/algorithms.html#c.PSA_ALG_IS_KEY_DERIVATION" title="PSA_ALG_IS_KEY_DERIVATION">PSA_ALG_IS_KEY_DERIVATION</a>(alg) \ |
| 128 | (((alg) & 0x7f000000) == 0x08000000) |
| 129 | |
| 130 | #define <a class="reference internal" href="../api/ops/algorithms.html#c.PSA_ALG_IS_MAC" title="PSA_ALG_IS_MAC">PSA_ALG_IS_MAC</a>(alg) \ |
| 131 | (((alg) & 0x7f000000) == 0x03000000) |
| 132 | |
| 133 | #define <a class="reference internal" href="../api/ops/sign.html#c.PSA_ALG_IS_RANDOMIZED_ECDSA" title="PSA_ALG_IS_RANDOMIZED_ECDSA">PSA_ALG_IS_RANDOMIZED_ECDSA</a>(alg) \ |
| 134 | (((alg) & ~0x000000ff) == 0x06000600) |
| 135 | |
| 136 | #define <a class="reference internal" href="../api/ops/ka.html#c.PSA_ALG_IS_RAW_KEY_AGREEMENT" title="PSA_ALG_IS_RAW_KEY_AGREEMENT">PSA_ALG_IS_RAW_KEY_AGREEMENT</a>(alg) \ |
| 137 | (((alg) & 0x7f00ffff) == 0x09000000) |
| 138 | |
| 139 | #define <a class="reference internal" href="../api/ops/pke.html#c.PSA_ALG_IS_RSA_OAEP" title="PSA_ALG_IS_RSA_OAEP">PSA_ALG_IS_RSA_OAEP</a>(alg) \ |
| 140 | (((alg) & ~0x000000ff) == 0x07000300) |
| 141 | |
| 142 | #define <a class="reference internal" href="../api/ops/sign.html#c.PSA_ALG_IS_RSA_PKCS1V15_SIGN" title="PSA_ALG_IS_RSA_PKCS1V15_SIGN">PSA_ALG_IS_RSA_PKCS1V15_SIGN</a>(alg) \ |
| 143 | (((alg) & ~0x000000ff) == 0x06000200) |
| 144 | |
| 145 | #define <a class="reference internal" href="../api/ops/sign.html#c.PSA_ALG_IS_RSA_PSS" title="PSA_ALG_IS_RSA_PSS">PSA_ALG_IS_RSA_PSS</a>(alg) \ |
| 146 | (((alg) & ~0x000000ff) == 0x06000300) |
| 147 | |
| 148 | #define <a class="reference internal" href="../api/ops/algorithms.html#c.PSA_ALG_IS_SIGN" title="PSA_ALG_IS_SIGN">PSA_ALG_IS_SIGN</a>(alg) \ |
| 149 | (((alg) & 0x7f000000) == 0x06000000) |
| 150 | |
| 151 | #define <a class="reference internal" href="../api/ops/sign.html#c.PSA_ALG_IS_SIGN_HASH" title="PSA_ALG_IS_SIGN_HASH">PSA_ALG_IS_SIGN_HASH</a>(alg) \ |
| 152 | <a class="reference internal" href="../api/ops/algorithms.html#c.PSA_ALG_IS_SIGN" title="PSA_ALG_IS_SIGN">PSA_ALG_IS_SIGN</a>(alg) |
| 153 | |
| 154 | #define <a class="reference internal" href="../api/ops/sign.html#c.PSA_ALG_IS_SIGN_MESSAGE" title="PSA_ALG_IS_SIGN_MESSAGE">PSA_ALG_IS_SIGN_MESSAGE</a>(alg) \ |
| 155 | (<a class="reference internal" href="../api/ops/algorithms.html#c.PSA_ALG_IS_SIGN" title="PSA_ALG_IS_SIGN">PSA_ALG_IS_SIGN</a>(alg) && \ |
| 156 | (alg) != <a class="reference internal" href="../api/ops/sign.html#c.PSA_ALG_ECDSA_ANY" title="PSA_ALG_ECDSA_ANY">PSA_ALG_ECDSA_ANY</a> && (alg) != <a class="reference internal" href="../api/ops/sign.html#c.PSA_ALG_RSA_PKCS1V15_SIGN_RAW" title="PSA_ALG_RSA_PKCS1V15_SIGN_RAW">PSA_ALG_RSA_PKCS1V15_SIGN_RAW</a>) |
| 157 | |
| 158 | #define <a class="reference internal" href="../api/ops/ciphers.html#c.PSA_ALG_IS_STREAM_CIPHER" title="PSA_ALG_IS_STREAM_CIPHER">PSA_ALG_IS_STREAM_CIPHER</a>(alg) \ |
| 159 | (((alg) & 0x7f800000) == 0x04800000) |
| 160 | |
| 161 | #define <a class="reference internal" href="../api/ops/kdf.html#c.PSA_ALG_IS_TLS12_PRF" title="PSA_ALG_IS_TLS12_PRF">PSA_ALG_IS_TLS12_PRF</a>(alg) \ |
| 162 | (((alg) & ~0x000000ff) == 0x08000200) |
| 163 | |
| 164 | #define <a class="reference internal" href="../api/ops/kdf.html#c.PSA_ALG_IS_TLS12_PSK_TO_MS" title="PSA_ALG_IS_TLS12_PSK_TO_MS">PSA_ALG_IS_TLS12_PSK_TO_MS</a>(alg) \ |
| 165 | (((alg) & ~0x000000ff) == 0x08000300) |
| 166 | |
| 167 | #define <a class="reference internal" href="../api/ops/algorithms.html#c.PSA_ALG_IS_WILDCARD" title="PSA_ALG_IS_WILDCARD">PSA_ALG_IS_WILDCARD</a>(alg) \ |
| 168 | (<a class="reference internal" href="../api/ops/algorithms.html#c.PSA_ALG_GET_HASH" title="PSA_ALG_GET_HASH">PSA_ALG_GET_HASH</a>(alg) == PSA_ALG_HASH_ANY) |
| 169 | |
| 170 | #define <a class="reference internal" href="../api/ops/ka.html#c.PSA_ALG_KEY_AGREEMENT" title="PSA_ALG_KEY_AGREEMENT">PSA_ALG_KEY_AGREEMENT</a>(ka_alg, kdf_alg) \ |
| 171 | ((ka_alg) | (kdf_alg)) |
| 172 | |
| 173 | #define <a class="reference internal" href="../api/ops/ka.html#c.PSA_ALG_KEY_AGREEMENT_GET_BASE" title="PSA_ALG_KEY_AGREEMENT_GET_BASE">PSA_ALG_KEY_AGREEMENT_GET_BASE</a>(alg) \ |
| 174 | ((<a class="reference internal" href="../api/ops/algorithms.html#c.psa_algorithm_t" title="psa_algorithm_t">psa_algorithm_t</a>)((alg) & 0xffff0000)) |
| 175 | |
| 176 | #define <a class="reference internal" href="../api/ops/ka.html#c.PSA_ALG_KEY_AGREEMENT_GET_KDF" title="PSA_ALG_KEY_AGREEMENT_GET_KDF">PSA_ALG_KEY_AGREEMENT_GET_KDF</a>(alg) \ |
| 177 | ((<a class="reference internal" href="../api/ops/algorithms.html#c.psa_algorithm_t" title="psa_algorithm_t">psa_algorithm_t</a>)((alg) & 0xfe00ffff)) |
| 178 | |
| 179 | #define <a class="reference internal" href="../api/ops/pke.html#c.PSA_ALG_RSA_OAEP" title="PSA_ALG_RSA_OAEP">PSA_ALG_RSA_OAEP</a>(hash_alg) \ |
| 180 | ((<a class="reference internal" href="../api/ops/algorithms.html#c.psa_algorithm_t" title="psa_algorithm_t">psa_algorithm_t</a>)(0x07000300 | ((hash_alg) & 0x000000ff))) |
| 181 | |
| 182 | #define <a class="reference internal" href="../api/ops/sign.html#c.PSA_ALG_RSA_PKCS1V15_SIGN" title="PSA_ALG_RSA_PKCS1V15_SIGN">PSA_ALG_RSA_PKCS1V15_SIGN</a>(hash_alg) \ |
| 183 | ((<a class="reference internal" href="../api/ops/algorithms.html#c.psa_algorithm_t" title="psa_algorithm_t">psa_algorithm_t</a>)(0x06000200 | ((hash_alg) & 0x000000ff))) |
| 184 | |
| 185 | #define <a class="reference internal" href="../api/ops/sign.html#c.PSA_ALG_RSA_PSS" title="PSA_ALG_RSA_PSS">PSA_ALG_RSA_PSS</a>(hash_alg) \ |
| 186 | ((<a class="reference internal" href="../api/ops/algorithms.html#c.psa_algorithm_t" title="psa_algorithm_t">psa_algorithm_t</a>)(0x06000300 | ((hash_alg) & 0x000000ff))) |
| 187 | |
| 188 | #define <a class="reference internal" href="../api/ops/kdf.html#c.PSA_ALG_TLS12_PRF" title="PSA_ALG_TLS12_PRF">PSA_ALG_TLS12_PRF</a>(hash_alg) \ |
| 189 | ((<a class="reference internal" href="../api/ops/algorithms.html#c.psa_algorithm_t" title="psa_algorithm_t">psa_algorithm_t</a>) (0x08000200 | ((hash_alg) & 0x000000ff))) |
| 190 | |
| 191 | #define <a class="reference internal" href="../api/ops/kdf.html#c.PSA_ALG_TLS12_PSK_TO_MS" title="PSA_ALG_TLS12_PSK_TO_MS">PSA_ALG_TLS12_PSK_TO_MS</a>(hash_alg) \ |
| 192 | ((<a class="reference internal" href="../api/ops/algorithms.html#c.psa_algorithm_t" title="psa_algorithm_t">psa_algorithm_t</a>) (0x08000300 | ((hash_alg) & 0x000000ff))) |
| 193 | |
| 194 | #define <a class="reference internal" href="../api/ops/macs.html#c.PSA_ALG_TRUNCATED_MAC" title="PSA_ALG_TRUNCATED_MAC">PSA_ALG_TRUNCATED_MAC</a>(mac_alg, mac_length) \ |
| 195 | ((<a class="reference internal" href="../api/ops/algorithms.html#c.psa_algorithm_t" title="psa_algorithm_t">psa_algorithm_t</a>) (((mac_alg) & ~0x003f0000) | (((mac_length) & 0x3f) << 16))) |
| 196 | </pre> |
Gilles Peskine | 6c723a2 | 2020-04-17 16:57:52 +0200 | [diff] [blame] | 197 | </div> |
| 198 | <div class="section" id="key-type-macros"> |
| 199 | <h2>Key type macros</h2> |
Gilles Peskine | c2db5f0 | 2021-01-18 20:36:53 +0100 | [diff] [blame^] | 200 | <pre class="literal-block"> |
| 201 | #define <a class="reference internal" href="../api/ops/ciphers.html#c.PSA_BLOCK_CIPHER_BLOCK_LENGTH" title="PSA_BLOCK_CIPHER_BLOCK_LENGTH">PSA_BLOCK_CIPHER_BLOCK_LENGTH</a>(type) \ |
| 202 | (1u << (((type) >> 8) & 7)) |
| 203 | |
| 204 | #define <a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_DH_GET_FAMILY" title="PSA_KEY_TYPE_DH_GET_FAMILY">PSA_KEY_TYPE_DH_GET_FAMILY</a>(type) \ |
| 205 | ((<a class="reference internal" href="../api/keys/types.html#c.psa_dh_family_t" title="psa_dh_family_t">psa_dh_family_t</a>) ((type) & 0x00ff)) |
| 206 | |
| 207 | #define <a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_DH_KEY_PAIR" title="PSA_KEY_TYPE_DH_KEY_PAIR">PSA_KEY_TYPE_DH_KEY_PAIR</a>(group) \ |
| 208 | ((<a class="reference internal" href="../api/keys/types.html#c.psa_key_type_t" title="psa_key_type_t">psa_key_type_t</a>) (0x7200 | (group))) |
| 209 | |
| 210 | #define <a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_DH_PUBLIC_KEY" title="PSA_KEY_TYPE_DH_PUBLIC_KEY">PSA_KEY_TYPE_DH_PUBLIC_KEY</a>(group) \ |
| 211 | ((<a class="reference internal" href="../api/keys/types.html#c.psa_key_type_t" title="psa_key_type_t">psa_key_type_t</a>) (0x4200 | (group))) |
| 212 | |
| 213 | #define <a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_ECC_GET_FAMILY" title="PSA_KEY_TYPE_ECC_GET_FAMILY">PSA_KEY_TYPE_ECC_GET_FAMILY</a>(type) \ |
| 214 | ((<a class="reference internal" href="../api/keys/types.html#c.psa_ecc_family_t" title="psa_ecc_family_t">psa_ecc_family_t</a>) ((type) & 0x00ff)) |
| 215 | |
| 216 | #define <a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_ECC_KEY_PAIR" title="PSA_KEY_TYPE_ECC_KEY_PAIR">PSA_KEY_TYPE_ECC_KEY_PAIR</a>(curve) \ |
| 217 | ((<a class="reference internal" href="../api/keys/types.html#c.psa_key_type_t" title="psa_key_type_t">psa_key_type_t</a>) (0x7100 | (curve))) |
| 218 | |
| 219 | #define <a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_ECC_PUBLIC_KEY" title="PSA_KEY_TYPE_ECC_PUBLIC_KEY">PSA_KEY_TYPE_ECC_PUBLIC_KEY</a>(curve) \ |
| 220 | ((<a class="reference internal" href="../api/keys/types.html#c.psa_key_type_t" title="psa_key_type_t">psa_key_type_t</a>) (0x4100 | (curve))) |
| 221 | |
| 222 | #define <a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_IS_ASYMMETRIC" title="PSA_KEY_TYPE_IS_ASYMMETRIC">PSA_KEY_TYPE_IS_ASYMMETRIC</a>(type) \ |
| 223 | (((type) & 0x4000) == 0x4000) |
| 224 | |
| 225 | #define <a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_IS_DH" title="PSA_KEY_TYPE_IS_DH">PSA_KEY_TYPE_IS_DH</a>(type) \ |
| 226 | ((<a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR" title="PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR">PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR</a>(type) & 0xff00) == 0x4200) |
| 227 | |
| 228 | #define <a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_IS_DH_KEY_PAIR" title="PSA_KEY_TYPE_IS_DH_KEY_PAIR">PSA_KEY_TYPE_IS_DH_KEY_PAIR</a>(type) \ |
| 229 | (((type) & 0xff00) == 0x7200) |
| 230 | |
| 231 | #define <a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_IS_DH_PUBLIC_KEY" title="PSA_KEY_TYPE_IS_DH_PUBLIC_KEY">PSA_KEY_TYPE_IS_DH_PUBLIC_KEY</a>(type) \ |
| 232 | (((type) & 0xff00) == 0x4200) |
| 233 | |
| 234 | #define <a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_IS_ECC" title="PSA_KEY_TYPE_IS_ECC">PSA_KEY_TYPE_IS_ECC</a>(type) \ |
| 235 | ((<a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR" title="PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR">PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR</a>(type) & 0xff00) == 0x4100) |
| 236 | |
| 237 | #define <a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_IS_ECC_KEY_PAIR" title="PSA_KEY_TYPE_IS_ECC_KEY_PAIR">PSA_KEY_TYPE_IS_ECC_KEY_PAIR</a>(type) \ |
| 238 | (((type) & 0xff00) == 0x7100) |
| 239 | |
| 240 | #define <a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY" title="PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY">PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY</a>(type) \ |
| 241 | (((type) & 0xff00) == 0x4100) |
| 242 | |
| 243 | #define <a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_IS_KEY_PAIR" title="PSA_KEY_TYPE_IS_KEY_PAIR">PSA_KEY_TYPE_IS_KEY_PAIR</a>(type) \ |
| 244 | (((type) & 0x7000) == 0x7000) |
| 245 | |
| 246 | #define <a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_IS_PUBLIC_KEY" title="PSA_KEY_TYPE_IS_PUBLIC_KEY">PSA_KEY_TYPE_IS_PUBLIC_KEY</a>(type) \ |
| 247 | (((type) & 0x7000) == 0x4000) |
| 248 | |
| 249 | #define <a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_IS_RSA" title="PSA_KEY_TYPE_IS_RSA">PSA_KEY_TYPE_IS_RSA</a>(type) \ |
| 250 | (<a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR" title="PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR">PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR</a>(type) == 0x4001) |
| 251 | |
| 252 | #define <a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_IS_UNSTRUCTURED" title="PSA_KEY_TYPE_IS_UNSTRUCTURED">PSA_KEY_TYPE_IS_UNSTRUCTURED</a>(type) \ |
| 253 | (((type) & 0x7000) == 0x1000 || ((type) & 0x7000) == 0x2000) |
| 254 | |
| 255 | #define <a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_KEY_PAIR_OF_PUBLIC_KEY" title="PSA_KEY_TYPE_KEY_PAIR_OF_PUBLIC_KEY">PSA_KEY_TYPE_KEY_PAIR_OF_PUBLIC_KEY</a>(type) \ |
| 256 | ((<a class="reference internal" href="../api/keys/types.html#c.psa_key_type_t" title="psa_key_type_t">psa_key_type_t</a>) ((type) | 0x3000)) |
| 257 | |
| 258 | #define <a class="reference internal" href="../api/keys/types.html#c.PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR" title="PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR">PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR</a>(type) \ |
| 259 | ((<a class="reference internal" href="../api/keys/types.html#c.psa_key_type_t" title="psa_key_type_t">psa_key_type_t</a>) ((type) & ~0x3000)) |
| 260 | </pre> |
Gilles Peskine | 6c723a2 | 2020-04-17 16:57:52 +0200 | [diff] [blame] | 261 | </div> |
| 262 | <div class="section" id="hash-suspend-state-macros"> |
| 263 | <h2>Hash suspend state macros</h2> |
Gilles Peskine | c2db5f0 | 2021-01-18 20:36:53 +0100 | [diff] [blame^] | 264 | <pre class="literal-block"> |
| 265 | #define <a class="reference internal" href="../api/ops/hashes.html#c.PSA_HASH_SUSPEND_HASH_STATE_FIELD_LENGTH" title="PSA_HASH_SUSPEND_HASH_STATE_FIELD_LENGTH">PSA_HASH_SUSPEND_HASH_STATE_FIELD_LENGTH</a>(alg) \ |
| 266 | ((alg)==<a class="reference internal" href="../api/ops/hashes.html#c.PSA_ALG_MD2" title="PSA_ALG_MD2">PSA_ALG_MD2</a> ? 64 : \ |
| 267 | (alg)==<a class="reference internal" href="../api/ops/hashes.html#c.PSA_ALG_MD4" title="PSA_ALG_MD4">PSA_ALG_MD4</a> || (alg)==<a class="reference internal" href="../api/ops/hashes.html#c.PSA_ALG_MD5" title="PSA_ALG_MD5">PSA_ALG_MD5</a> ? 16 : \ |
| 268 | (alg)==<a class="reference internal" href="../api/ops/hashes.html#c.PSA_ALG_RIPEMD160" title="PSA_ALG_RIPEMD160">PSA_ALG_RIPEMD160</a> || (alg)==<a class="reference internal" href="../api/ops/hashes.html#c.PSA_ALG_SHA_1" title="PSA_ALG_SHA_1">PSA_ALG_SHA_1</a> ? 20 : \ |
| 269 | (alg)==<a class="reference internal" href="../api/ops/hashes.html#c.PSA_ALG_SHA_224" title="PSA_ALG_SHA_224">PSA_ALG_SHA_224</a> || (alg)==<a class="reference internal" href="../api/ops/hashes.html#c.PSA_ALG_SHA_256" title="PSA_ALG_SHA_256">PSA_ALG_SHA_256</a> ? 32 : \ |
| 270 | (alg)==<a class="reference internal" href="../api/ops/hashes.html#c.PSA_ALG_SHA_512" title="PSA_ALG_SHA_512">PSA_ALG_SHA_512</a> || (alg)==<a class="reference internal" href="../api/ops/hashes.html#c.PSA_ALG_SHA_384" title="PSA_ALG_SHA_384">PSA_ALG_SHA_384</a> || (alg)==<a class="reference internal" href="../api/ops/hashes.html#c.PSA_ALG_SHA_512_256" title="PSA_ALG_SHA_512_256">PSA_ALG_SHA_512_256</a> ? 64 : \ |
| 271 | 0) |
| 272 | |
| 273 | #define <a class="reference internal" href="../api/ops/hashes.html#c.PSA_HASH_SUSPEND_INPUT_LENGTH_FIELD_LENGTH" title="PSA_HASH_SUSPEND_INPUT_LENGTH_FIELD_LENGTH">PSA_HASH_SUSPEND_INPUT_LENGTH_FIELD_LENGTH</a>(alg) \ |
| 274 | ((alg)==<a class="reference internal" href="../api/ops/hashes.html#c.PSA_ALG_MD2" title="PSA_ALG_MD2">PSA_ALG_MD2</a> ? 1 : \ |
| 275 | (alg)==<a class="reference internal" href="../api/ops/hashes.html#c.PSA_ALG_MD4" title="PSA_ALG_MD4">PSA_ALG_MD4</a> || (alg)==<a class="reference internal" href="../api/ops/hashes.html#c.PSA_ALG_MD5" title="PSA_ALG_MD5">PSA_ALG_MD5</a> || (alg)==<a class="reference internal" href="../api/ops/hashes.html#c.PSA_ALG_RIPEMD160" title="PSA_ALG_RIPEMD160">PSA_ALG_RIPEMD160</a> || \ |
| 276 | (alg)==<a class="reference internal" href="../api/ops/hashes.html#c.PSA_ALG_SHA_1" title="PSA_ALG_SHA_1">PSA_ALG_SHA_1</a> || (alg)==<a class="reference internal" href="../api/ops/hashes.html#c.PSA_ALG_SHA_224" title="PSA_ALG_SHA_224">PSA_ALG_SHA_224</a> || (alg)==<a class="reference internal" href="../api/ops/hashes.html#c.PSA_ALG_SHA_256" title="PSA_ALG_SHA_256">PSA_ALG_SHA_256</a> ? 8 : \ |
| 277 | (alg)==<a class="reference internal" href="../api/ops/hashes.html#c.PSA_ALG_SHA_512" title="PSA_ALG_SHA_512">PSA_ALG_SHA_512</a> || (alg)==<a class="reference internal" href="../api/ops/hashes.html#c.PSA_ALG_SHA_384" title="PSA_ALG_SHA_384">PSA_ALG_SHA_384</a> || (alg)==<a class="reference internal" href="../api/ops/hashes.html#c.PSA_ALG_SHA_512_256" title="PSA_ALG_SHA_512_256">PSA_ALG_SHA_512_256</a> ? 16 : \ |
| 278 | 0) |
| 279 | |
| 280 | #define <a class="reference internal" href="../api/ops/hashes.html#c.PSA_HASH_SUSPEND_OUTPUT_SIZE" title="PSA_HASH_SUSPEND_OUTPUT_SIZE">PSA_HASH_SUSPEND_OUTPUT_SIZE</a>(alg) \ |
| 281 | (<a class="reference internal" href="../api/ops/hashes.html#c.PSA_HASH_SUSPEND_ALGORITHM_FIELD_LENGTH" title="PSA_HASH_SUSPEND_ALGORITHM_FIELD_LENGTH">PSA_HASH_SUSPEND_ALGORITHM_FIELD_LENGTH</a> + \ |
| 282 | <a class="reference internal" href="../api/ops/hashes.html#c.PSA_HASH_SUSPEND_INPUT_LENGTH_FIELD_LENGTH" title="PSA_HASH_SUSPEND_INPUT_LENGTH_FIELD_LENGTH">PSA_HASH_SUSPEND_INPUT_LENGTH_FIELD_LENGTH</a>(alg) + \ |
| 283 | <a class="reference internal" href="../api/ops/hashes.html#c.PSA_HASH_SUSPEND_HASH_STATE_FIELD_LENGTH" title="PSA_HASH_SUSPEND_HASH_STATE_FIELD_LENGTH">PSA_HASH_SUSPEND_HASH_STATE_FIELD_LENGTH</a>(alg) + \ |
| 284 | <a class="reference internal" href="../api/ops/hashes.html#c.PSA_HASH_BLOCK_LENGTH" title="PSA_HASH_BLOCK_LENGTH">PSA_HASH_BLOCK_LENGTH</a>(alg) - 1) |
| 285 | </pre> |
Gilles Peskine | 6c723a2 | 2020-04-17 16:57:52 +0200 | [diff] [blame] | 286 | </div> |
| 287 | </div> |
| 288 | |
| 289 | |
| 290 | </div> |
| 291 | </div> |
| 292 | </div> |
| 293 | <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> |
Gilles Peskine | c2db5f0 | 2021-01-18 20:36:53 +0100 | [diff] [blame^] | 294 | <div class="sphinxsidebarwrapper"><h3><a href="../index.html"><b>PSA Crypto API</b></a></h3> |
| 295 | IHI 0086<br/> |
| 296 | Non-confidential<br/> |
| 297 | Version 1.0.1 |
| 298 | <span style="color: red; font-weight: bold;"></span> |
| 299 | <ul> |
| 300 | <li class="toctree-l1"><a class="reference internal" href="../about.html">About this document</a></li> |
| 301 | </ul> |
| 302 | <ul> |
| 303 | <li class="toctree-l1"><a class="reference internal" href="../overview/intro.html">1. Introduction</a></li> |
| 304 | <li class="toctree-l1"><a class="reference internal" href="../overview/goals.html">2. Design goals</a></li> |
| 305 | <li class="toctree-l1"><a class="reference internal" href="../overview/functionality.html">3. Functionality overview</a></li> |
| 306 | <li class="toctree-l1"><a class="reference internal" href="../overview/sample-arch.html">4. Sample architectures</a></li> |
| 307 | <li class="toctree-l1"><a class="reference internal" href="../overview/conventions.html">5. Library conventions</a></li> |
| 308 | <li class="toctree-l1"><a class="reference internal" href="../overview/implementation.html">6. Implementation considerations</a></li> |
| 309 | <li class="toctree-l1"><a class="reference internal" href="../overview/usage.html">7. Usage considerations</a></li> |
| 310 | <li class="toctree-l1"><a class="reference internal" href="../api/library/index.html">8. Library management reference</a></li> |
| 311 | <li class="toctree-l1"><a class="reference internal" href="../api/keys/index.html">9. Key management reference</a></li> |
| 312 | <li class="toctree-l1"><a class="reference internal" href="../api/ops/index.html">10. Cryptographic operation reference</a></li> |
| 313 | </ul> |
| 314 | <ul class="current"> |
| 315 | <li class="toctree-l1"><a class="reference internal" href="example_header.html">Example header file</a></li> |
| 316 | <li class="toctree-l1 current"><a class="current reference internal" href="#">Example macro implementations</a><ul> |
| 317 | <li class="toctree-l2"><a class="reference internal" href="#algorithm-macros">Algorithm macros</a></li> |
| 318 | <li class="toctree-l2"><a class="reference internal" href="#key-type-macros">Key type macros</a></li> |
| 319 | <li class="toctree-l2"><a class="reference internal" href="#hash-suspend-state-macros">Hash suspend state macros</a></li> |
Gilles Peskine | 6c723a2 | 2020-04-17 16:57:52 +0200 | [diff] [blame] | 320 | </ul> |
| 321 | </li> |
Gilles Peskine | c2db5f0 | 2021-01-18 20:36:53 +0100 | [diff] [blame^] | 322 | <li class="toctree-l1"><a class="reference internal" href="history.html">Changes to the API</a></li> |
Gilles Peskine | 6c723a2 | 2020-04-17 16:57:52 +0200 | [diff] [blame] | 323 | </ul> |
Gilles Peskine | 6c723a2 | 2020-04-17 16:57:52 +0200 | [diff] [blame] | 324 | <ul> |
Gilles Peskine | c2db5f0 | 2021-01-18 20:36:53 +0100 | [diff] [blame^] | 325 | <li class="toctree-l1"><a class="reference internal" href="../psa_c-identifiers.html">Index of API elements</a></li> |
Gilles Peskine | 6c723a2 | 2020-04-17 16:57:52 +0200 | [diff] [blame] | 326 | </ul> |
Gilles Peskine | 6c723a2 | 2020-04-17 16:57:52 +0200 | [diff] [blame] | 327 | <div id="searchbox" style="display: none" role="search"> |
| 328 | <h3>Quick search</h3> |
| 329 | <form class="search" action="../search.html" method="get"> |
| 330 | <div><input type="text" name="q" /></div> |
| 331 | <div><input type="submit" value="Go" /></div> |
| 332 | <input type="hidden" name="check_keywords" value="yes" /> |
| 333 | <input type="hidden" name="area" value="default" /> |
| 334 | </form> |
| 335 | </div> |
| 336 | <script type="text/javascript">$('#searchbox').show(0);</script> |
| 337 | </div> |
| 338 | </div> |
| 339 | <div class="clearer"></div> |
| 340 | </div> |
| 341 | <div class="footer"> |
Gilles Peskine | c2db5f0 | 2021-01-18 20:36:53 +0100 | [diff] [blame^] | 342 | © 2018-2020, Arm Limited or its affiliates. All rights reserved. |
Gilles Peskine | 6c723a2 | 2020-04-17 16:57:52 +0200 | [diff] [blame] | 343 | |
| 344 | | |
| 345 | Powered by <a href="http://sphinx-doc.org/">Sphinx 1.6.7</a> |
| 346 | & <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.8</a> |
| 347 | |
Gilles Peskine | 6c723a2 | 2020-04-17 16:57:52 +0200 | [diff] [blame] | 348 | </div> |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | </body> |
| 354 | </html> |