* Start the CBC-MAC process. This handles the auth data. */
| 86 | * Start the CBC-MAC process. This handles the auth data. |
| 87 | */ |
| 88 | static __m128i |
| 89 | cbc_mac_start(const unsigned char *auth_data, size_t auth_len, |
| 90 | const unsigned char *nonce, size_t nonce_len, |
| 91 | const unsigned char *key, int nr, |
| 92 | size_t data_len, size_t tag_len) |
| 93 | { |
| 94 | __m128i cbc_block, staging_block; |
| 95 | uint8_t *byte_ptr; |
| 96 | /* This defines where the message length goes */ |
| 97 | int L = sizeof(__m128i) - 1 - nonce_len; |
| 98 | |
| 99 | /* |
| 100 | * Set up B0 here. This has the flags byte, |
| 101 | * followed by the nonce, followed by the |
| 102 | * length of the message. |
| 103 | */ |
| 104 | cbc_block = _mm_setzero_si128(); |
| 105 | byte_ptr = (uint8_t*)&cbc_block; |
| 106 | byte_ptr[0] = ((auth_len > 0) ? 1 : 0) * 64 | |
| 107 | (((tag_len - 2) / 2) * 8) | |
| 108 | (L - 1); |
| 109 | bcopy(nonce, byte_ptr + 1, nonce_len); |
| 110 | append_int(data_len, &cbc_block, L+1); |
| 111 | cbc_block = AESNI_ENC(cbc_block, key, nr); |
| 112 | |
| 113 | if (auth_len != 0) { |
| 114 | /* |
| 115 | * We need to start by appending the length descriptor. |
| 116 | */ |
| 117 | uint32_t auth_amt; |
| 118 | size_t copy_amt; |
| 119 | const uint8_t *auth_ptr = auth_data; |
| 120 | |
| 121 | staging_block = _mm_setzero_si128(); |
| 122 | |
| 123 | /* |
| 124 | * The current OCF calling convention means that |
| 125 | * there can never be more than 4g of authentication |
| 126 | * data, so we don't handle the 0xffff case. |
| 127 | */ |
| 128 | KASSERT(auth_len < (1ULL << 32), |
| 129 | ("%s: auth_len (%zu) larger than 4GB", |
| 130 | __FUNCTION__, auth_len)); |
| 131 | |
| 132 | if (auth_len < ((1 << 16) - (1 << 8))) { |
| 133 | /* |
| 134 | * If the auth data length is less than |
| 135 | * 0xff00, we don't need to encode a length |
| 136 | * specifier, just the length of the auth |
| 137 | * data. |
| 138 | */ |
| 139 | be16enc(&staging_block, auth_len); |
| 140 | auth_amt = 2; |
| 141 | } else if (auth_len < (1ULL << 32)) { |
| 142 | /* |
| 143 | * Two bytes for the length prefix, and then |
| 144 | * four bytes for the length. This makes a total |
| 145 | * of 6 bytes to describe the auth data length. |
no test coverage detected