Skip to content

dspearson/azjure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

303 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

azjure

Encryption in Clojure

Version

Clojars Project

Status

Build Status

Project Setup

Add the following in the dependencies section of your project.clj file

:dependencies [...
               [azjure "1.0.0-SNAPSHOT"]
               ...]

Configuration Map

Each function in the API uses map to configure the behavior of the encrypt/decrypt functions.

The map has the following format:

{:type :typekw
 :mode :modekw
 :pad  :padderkw
 :eid  :input-decoderkw
 :eoe  :output-encoderkw
 :did  :input-decoderkw
 :doe  :output-encoderkw
 :key  []
 :iv   []}
  • type - A keyword that identifies the cipher you wish to use. See cipher.clj for supported values.
  • mode - A keyword that identifies the block chaining mode you wish to use. See modes.clj for supported values.
  • pad - A keyword that identifies the padder you wish to use. See padders.clj for supported values.
  • eid - A keyword that represents the encryption input decoder you wish to use. See encoders.clj for supported values.
  • eoe - A keyword that represents the encryption output encoder you wish to use. See encoders.clj for supported values.
  • did - A keyword that represents the decryption input decoder you wish to use. See encoders.clj for supported values.
  • doe - A keyword that represents the decryption output encoder you wish to use. See encoders.clj for supported values.
  • key - A vector of unsigned bytes (0-255) of the appropriate length that represents the key you wish to use with the cipher.
  • iv - A vector of unsigned bytes (0-255) of the appropriate length that represents the IV you wish to use with the block chaining mode.
  • nonce - A vector of unsigned bytes (0-255) of the appropriate length that represents the nonce you with to use with the stream cipher.

Block Cipher Usage (Quick)

(:require ...
          [azjure.core :refer :all]
          [azjure.cipher.aes :refer :all] 
          ;Require all the cipher(s) you wish to use
          ...
          )

Encrypt

;; Encrypt a vector of unsigned bytes
;; Note that the keys shown below are the required keys for a 
;; block cipher
(encrypt [0 0 0 0]
         {:type :aes :mode :ecb :pad :pkcs7
          :key [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
          :iv [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]})
;; Should evaluate to
;; [223 80 151 26 46 117 190 64 134 255 95 229 221 229 165 35]

Decrypt

;; Decrypt a vector of unsigned bytes
(decrypt [223 80 151 26 46 117 190 64 134 255 95 229 221 229 165 35]
         {:type :aes :mode :ecb :pad :pkcs7
          :key [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
          :iv [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]})
;; Should evaluate to [0 0 0 0]

Stream Cipher Usage (Quick)

(:require ...
          [azjure.core :refer :all]
          [azjure.cipher.salsa20 :refer :all]
          ;Require all the ciphers(s) you wish to use
          ...
          )

Encrypt/Decrypt

;; Generate ciphertext
;; Note that the keys shown below are the required keys for
;; a stream cipher
(encrypted-stream [0 0 0 0]
                  {:type :salsa20
                   :key [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
                   :nonce [0 0 0 0 0 0 0 0]})
;; Should evaluate to [101 19 173 174]

;; Generate plaintext
(encrypted-stream [101 19 173 174]
                  {:type :salsa20
                   :key [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
                   :nonce [0 0 0 0 0 0 0 0]})
;; Should evaluate to [0 0 0 0]

More Examples

See the examples documentation for more extensive usage examples

Supported Ciphers

Block

  1. Advanced Encryption Standard (AES) - FIPS 197
  2. Blowfish (BF) - Blowfish Spec
  3. CAST-256 (CAST6) - CAST-256 RFC
  4. Twofish (TF) - Twofish Spec
  5. TEA (TEA) - TEA Spec
  6. XTEA (XTEA) - XTEA Spec

Block - In Progress

  1. CAST-128 (CAST5) - CAST-128 RFC

Stream

  1. Salsa20 (Salsa20) - Salsa20 Spec
  2. ChaCha (Chacha) - ChaCha Spec

Stream - In Progress

  1. HC-128 (HC128) - HC-128 Spec
  2. HC-256 (HC256) - HC-256 Spec
  3. MICKEY2.0 (MICKEY2.0) - MICKEY2.0 Spec
  4. Rabbit (Rabbit) - Rabbit Spec
  5. Trivium (Trivium) - Trivium Spec

Supported Modes

Cipher modes describe the method for encrypting multiple blocks with block ciphers.

See Mode of Operation for descriptions

Block Only Modes

  1. Electronic Codebook (ECB)
  2. Cipher-Block Chaining (CBC)
  3. Propagating Cipher-Block Chaining (PCBC)

Modes able to use Block Ciphers as Stream Ciphers

  1. Cipher Feedback (CFB)
  2. Output Feedback (OFB)
  3. Counter (CTR)

Supported Padding

Some cipher modes (ECB, CBC, PCBC) require that the input be padded with bytes until a multiple of the cipher's blocksize. The following padding methods are supported.

See Padding for descriptions

  1. PKCS7
  2. Zero Byte
  3. ISO 10126
  4. ANSI X.923
  5. ISO/IEC 7816-4

Character Encoding/Decoding

By default the API works with vectors of unsigned bytes. However, there is built in support for converting to and from many common character encodings.

The following encodings are supported:

  1. str - ASCII character encoding
  2. hex - hex encoding (0-9a-f)
  3. base16 - Base16 encoding (0-9A-F)
  4. base32 - Base32 encoding (A-Z2-7)
  5. base32hex - Base32 encoding with a hex alphabet (0-9A-V)
  6. base64 - Base64 encoding (A-Za-z0-9+/)
  7. base64url - Base64 encoding with the URL safe alphabet (A-Za-z0-9-_)

About

Encryption in Clojure

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors