v/vlib/x/crypto/poly1305
2024-09-10 11:25:56 +03:00
..
custom.v all: change single blank comment to blank line (#22016) 2024-08-09 14:55:58 +03:00
poly1305.v fmt: remove the prefixed module name of const names, that are in the same module (related #22183) (#22185) 2024-09-10 11:25:56 +03:00
poly1305_test.v fmt: remove the prefixed module name of const names, that are in the same module (related #22183) (#22185) 2024-09-10 11:25:56 +03:00
README.md vlib.x: fix typos, uniformize readme formatting (#21085) 2024-03-24 19:54:39 +02:00
usage_test.v vlib.x: fix typos, uniformize readme formatting (#21085) 2024-03-24 19:54:39 +02:00

poly1305

Poly1305 is a one-time authenticator originally designed by D. J. Bernstein. Poly1305 takes a 32-byte one-time key and a message and produces a 16-byte tag. It can be used to verify the data integrity and the authenticity of a message.

This module provides generic poly1305 message authentication code (MAC) module in pure V.

As a note, a key must only be used for a single message. Authenticating two different messages with the same key allows an attacker to forge authenticators for other messages with the same key.

Warning

This is an experimental module, which is subject to change, please use it carefully and thoroughly

Examples

module main

import encoding.hex
import x.crypto.poly1305

fn main() {
	// this examples mostly based on rfc
	// provide yours secure key
	yourkey := '0000000000000000000000000000000036e5f6b5c5e06070f0efca96227a863e'
	key := hex.decode(yourkey)!

	// messages to be authenticated
	msg := 'Sample messages'.bytes()

	mut out := []u8{len: 16}
	// lets create tag (mac) stored into out
	poly1305.create_tag(mut out, msg, key)!
	status := poly1305.verify_tag(out, msg, key)
	assert status == true
}