libutil

C Utility Library
git clone http://git.omkov.net/libutil
Log | Tree | Refs | README | LICENCE | Download

libutil/src/test/test_crypt.c (54 lines, 1.4 KiB) -rw-r--r-- blame download

01234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
// test_crypt.c
// Crypt unit test for libutil
// Copyright (C) 2021, Jakob Wakeling
// MIT Licence

#include "../crypt.h"
#include "unit.h"

#include <stdint.h>
#include <stdio.h>

int main(void) {
	{
		ASSERT("G00T00 ROL8 1",
				ROL8(0xF0u, 1) == 0xE1u);
		ASSERT("G00T01 ROL8 7",
				ROL8(0xF0u, 7) == 0x78u);
		ASSERT("G00T02 ROL16 1",
				ROL16(0xF000u, 1) == 0xE001u);
		ASSERT("G00T03 ROL16 15",
				ROL16(0xF000u, 15) == 0x7800u);
		ASSERT("G00T04 ROL32 1",
				ROL32(0xF0000000uL, 1) == 0xE0000001uL);
		ASSERT("G00T05 ROL32 31",
				ROL32(0xF0000000uL, 31) == 0x78000000uL);
		ASSERT("G00T06 ROL64 1",
				ROL64(0xF000000000000000uLL, 1) == 0xE000000000000001uLL);
		ASSERT("G00T07 ROL64 63",
				ROL64(0xF000000000000000uLL, 63) == 0x7800000000000000uLL);
	}
	
	{
		ASSERT("G01T00 ROR8 1",
				ROR8(0x0Fu, 1) == 0x87u);
		ASSERT("G01T01 ROR8 7",
				ROR8(0x0Fu, 7) == 0x1Eu);
		ASSERT("G01T02 ROR16 1",
				ROR16(0x000Fu, 1) == 0x8007u);
		ASSERT("G01T03 ROR16 15",
				ROR16(0x000Fu, 15) == 0x001Eu);
		ASSERT("G01T04 ROR32 1",
				ROR32(0x0000000FuL, 1) == 0x80000007uL);
		ASSERT("G01T05 ROR32 31",
				ROR32(0x0000000FuL, 31) == 0x0000001EuL);
		ASSERT("G01T06 ROR64 1",
				ROR64(0x000000000000000FuLL, 1) == 0x8000000000000007uLL);
		ASSERT("G01T07 ROR64 63",
				ROR64(0x000000000000000FuLL, 63) == 0x000000000000001EuLL);
	}
	
	printf("%d of %d tests passed\n", testspassed, testsrun);
	return testsfailed;
}