| ... | ... | @@ -469,11 +469,15 @@ pub fn chacha20poly1305Seal(dst: []u8, plaintext: []const u8, data: []const u8, |
| 469 | 469 | mac.final(dst[plaintext.len..]); |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | /// Verifies and decrypts an authenticated message produced by chacha20poly1305Open. |
| 473 | /// Returns false if message was invalid or authentication failed. |
| 472 | 474 | pub fn chacha20poly1305Open(dst: []u8, ciphertext: []const u8, data: []const u8, key: [32]u8, nonce: [12]u8) bool { |
| 473 | | assert(ciphertext.len >= chacha20poly1305_tag_size); |
| 474 | | assert(dst.len >= ciphertext.len - chacha20poly1305_tag_size); |
| 475 | if (ciphertext.len < chacha20poly1305_tag_size) { |
| 476 | return false; |
| 477 | } |
| 475 | 478 | |
| 476 | 479 | // split ciphertext and tag |
| 480 | assert(dst.len >= ciphertext.len - chacha20poly1305_tag_size); |
| 477 | 481 | var polyTag = ciphertext[ciphertext.len - chacha20poly1305_tag_size ..]; |
| 478 | 482 | ciphertext = ciphertext[0 .. ciphertext.len - chacha20poly1305_tag_size]; |
| 479 | 483 | |