| 1 | // Copyright ©2025 blackshirt. |
| 2 | // Use of this source code is governed by an MIT license |
| 3 | // that can be found in the LICENSE file. |
| 4 | // |
| 5 | import encoding.hex |
| 6 | import x.crypto.ascon |
| 7 | |
| 8 | // The material was generated from https://hashing.tools/ascon/ascon-hash |
| 9 | fn main() { |
| 10 | msg := 'Example of CXof128 message'.bytes() |
| 11 | cs := 'custom-string-cxof128'.bytes() |
| 12 | |
| 13 | // expected output generated from the tool, with 32, 64 dan 75-bytes output |
| 14 | digest32 := hex.decode('d71492b816b1ac27f53f9c13be45c1d2d0530b8dde7fde8d34cb563f79b3d3d3')! |
| 15 | digest64 := |
| 16 | hex.decode('d71492b816b1ac27f53f9c13be45c1d2d0530b8dde7fde8d34cb563f79b3d3d3601d03474ec6fe1f6b8dc5dd79bea20aff4c95ca3549202b1aaeb9e66b5df398')! |
| 17 | digest75 := |
| 18 | hex.decode('d71492b816b1ac27f53f9c13be45c1d2d0530b8dde7fde8d34cb563f79b3d3d3601d03474ec6fe1f6b8dc5dd79bea20aff4c95ca3549202b1aaeb9e66b5df3985a88fd8bce0f9570962321')! |
| 19 | |
| 20 | out32 := ascon.cxof128(msg, 32, cs)! |
| 21 | out64 := ascon.cxof128(msg, 64, cs)! |
| 22 | out75 := ascon.cxof128(msg, 75, cs)! |
| 23 | dump(out32 == digest32) // out32 == digest32: true |
| 24 | dump(out64 == digest64) // out64 == digest64: true |
| 25 | dump(out75 == digest75) // out75 == digest75: true |
| 26 | |
| 27 | // With object based |
| 28 | mut x := ascon.new_cxof128(32, cs)! |
| 29 | s32 := x.sum(msg) |
| 30 | dump(s32 == digest32) // s32 == digest32: true |
| 31 | |
| 32 | // with sized output |
| 33 | x.reset() |
| 34 | _ := x.write(msg)! |
| 35 | mut b64 := []u8{len: 64} |
| 36 | _ := x.read(mut b64)! |
| 37 | dump(b64 == digest64) // b64 == digest64: true |
| 38 | |
| 39 | x.reset() |
| 40 | _ := x.write(msg)! |
| 41 | mut b75 := []u8{len: 75} |
| 42 | _ := x.read(mut b75)! |
| 43 | dump(b75 == digest75) // b75 == digest75: true |
| 44 | } |
| 45 | |