Skip to content

R/S Cryptographic Library #2

@qtxie

Description

@qtxie
Red/System []

#enum crypt-algorithm! [
	AES
	DES
	_3DES
	RC4
]

#enum block-chaining! [
	ECB
	CBC
	;CFB8
	;CFB64
	;CFB128
	GCM
	CCM
	;GMAC
	;CMAC
]

rs-crypt: context [
	#import [
		
	]

	verbose: 0

	#define DPrint(msg) [#if debug? = yes [if verbose > 0 [print-line msg]]]

	;== Symmetric Algorithms

	encypt-init: func [
		alg			[crypt-algorithm!]
		IV			[byte-ptr!]			;-- initialization vector
		key			[byte-ptr!]
		key-len		[uint!]				;-- AES: 128, 192 or 256, DES: 56, 3DES: 56, 112, 168
		chain-mode	[block-chaining!]	;-- CBC, ECB, GCM, etc
		return:		[handle!]			;-- null if error
	][
		DPrint("encypt-init")
	]

	encypt-update: func [
		hCrypt		[handle!]			;-- handle returned by make
		data		[byte-ptr!]
		data-len	[uint!]
		outbuf		[byte-ptr!]
		outlen		[int-ptr!]
		return:		[integer!]			;-- error code
	][]

	encrypt-final: func [
		hCrypt		[handle!]			;-- handle returned by make
		outbuf		[byte-ptr!]
		outlen		[int-ptr!]
		return:		[integer!]
	][]

	decrypt-init: func [
		alg			[crypt-algorithm!]
		IV			[byte-ptr!]			;-- initialization vector
		key			[byte-ptr!]
		key-len		[uint!]				;-- AES: 128, 192 or 256, DES: 56, 3DES: 56, 112, 168
		chain-mode	[block-chaining!]	;-- CBC, ECB, GCM, etc
		return:		[handle!]			;-- null if error
	][]

	decrypt-update: func [
		hCrypt		[handle!]			;-- handle returned by make
		data		[byte-ptr!]
		data-len	[uint!]
		outbuf		[byte-ptr!]
		outlen		[int-ptr!]
		return:		[integer!]			;-- error code
	][]

	decrypt-final: func [
		hCrypt		[handle!]			;-- handle returned by make
		outbuf		[byte-ptr!]
		outlen		[int-ptr!]
		return:		[integer!]
	][]

	set-property: func [				;-- set IV length, tag length, etc.
		hCrypt		[handle!]			;-- handle returned by make
		property	[integer!]
		input		[byte-ptr!]
		input-len	[integer!]
		return:		[integer!]
	]

	get-property: func [
		hCrypt		[handle!]			;-- handle returned by make
		property	[integer!]
		output		[byte-ptr!]
		output-len	[int-ptr!]
		return:		[integer!]	
	]

	;== Asymmetric Algorithms
	;-- RSA

	;-- DSA

	;== Key Exchange Algorithms
	;-- ECDH, ECDSA, etc

	;== Hashing Algorithms
	;-- SHA, MD5, etc

]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions