hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

block.ha (946B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 // An abstract interface for implementing block ciphers.
      5 export type blockvtable = struct {
      6 	blocksz: size,
      7 
      8 	nparallel: size,
      9 
     10 	encrypt: *fn(b: *block, dest: []u8, src: []u8) void,
     11 	decrypt: *fn(b: *block, dest: []u8, src: []u8) void,
     12 	finish: *fn(b: *block) void,
     13 };
     14 
     15 export type block = *blockvtable;
     16 
     17 // Returns the block size in bytes for a [[block]] cipher.
     18 export fn blocksz(b: *block) size = b.blocksz;
     19 
     20 // Returns the number of blocks that can be processed at once for a [[block]]
     21 // cipher.
     22 export fn nparallel(b: *block) size = b.nparallel;
     23 
     24 // Encrypt up to [[nparallel]] blocks from 'src' and writes to 'dest'.
     25 export fn encrypt(b: *block, dest: []u8, src: []u8) void =
     26 	b.encrypt(b, dest, src);
     27 
     28 // Decrypt up to [[nparallel]] blocks from 'src' and writes to 'dest'.
     29 export fn decrypt(b: *block, dest: []u8, src: []u8) void =
     30 	b.decrypt(b, dest, src);