Arduino Cryptography Library: ChaChaPoly Class Reference (2024)

Authenticated cipher based on ChaCha and Poly1305. More...

#include <ChaChaPoly.h>

Inheritance diagram for ChaChaPoly:

Arduino Cryptography Library: ChaChaPoly Class Reference (1)

AuthenticatedCipherCipher

Public Member Functions

ChaChaPoly ()
Constructs a new ChaChaPoly authenticated cipher.
virtual~ChaChaPoly ()
Destroys this ChaChaPoly authenticated cipher.
size_tkeySize () const
Default size of the key for this cipher, in bytes. More...
size_tivSize () const
Size of the initialization vector for this cipher, in bytes. More...
size_ttagSize () const
Returns the size of the authentication tag. More...
boolsetKey (const uint8_t *key, size_t len)
Sets the key to use for future encryption and decryption operations. More...
boolsetIV (const uint8_t *iv, size_t len)
Sets the initialization vector to use for future encryption and decryption operations. More...
voidencrypt (uint8_t *output, const uint8_t *input, size_t len)
Encrypts an input buffer and writes the ciphertext to an output buffer. More...
voiddecrypt (uint8_t *output, const uint8_t *input, size_t len)
Decrypts an input buffer and writes the plaintext to an output buffer. More...
voidaddAuthData (const void *data, size_t len)
Adds extra data that will be authenticated but not encrypted. More...
voidcomputeTag (void *tag, size_t len)
Finalizes the encryption process and computes the authentication tag. More...
boolcheckTag (const void *tag, size_t len)
Finalizes the decryption process and checks the authentication tag. More...
voidclear ()
Clears all security-sensitive state from this cipher. More...
Arduino Cryptography Library: ChaChaPoly Class Reference (2)Public Member Functions inherited from AuthenticatedCipher
AuthenticatedCipher ()
Constructs a new authenticated cipher.
virtual~AuthenticatedCipher ()
Destroys this authenticated cipher.
Arduino Cryptography Library: ChaChaPoly Class Reference (3)Public Member Functions inherited from Cipher
Cipher ()
Constructs a new cipher object.
virtual~Cipher ()
Destroys this cipher object. More...

Detailed Description

Authenticated cipher based on ChaCha and Poly1305.

ChaChaPoly is an authenticated cipher based on a combination of ChaCha with 20 rounds for encryption and Poly1305 for authentication. The resulting cipher has a 256-bit key, a 64-bit or 96-bit initialization vector, and a 128-bit authentication tag.

Reference: https://tools.ietf.org/html/draft-irtf-cfrg-chacha20-poly1305-10

See also
ChaCha, Poly1305, AuthenticatedCipher

Definition at line 30 of file ChaChaPoly.h.

Member Function Documentation

addAuthData()

void ChaChaPoly::addAuthData ( const void * data,
size_t len
)
virtual

Adds extra data that will be authenticated but not encrypted.

Parameters
dataThe extra data to be authenticated.
lenThe number of bytes of extra data to be authenticated.

This function must be called before the first call to encrypt() or decrypt(). That is, it is assumed that all extra data for authentication is available before the first payload data block and that it will be prepended to the payload for authentication. If the subclass needs to process the extra data after the payload, then it is responsible for saving data away until it is needed during computeTag() or checkTag().

This function can be called multiple times with separate extra data blocks for authentication. All such data will be concatenated into a single block for authentication purposes.

Implements AuthenticatedCipher.

Definition at line 127 of file ChaChaPoly.cpp.

checkTag()

bool ChaChaPoly::checkTag ( const void * tag,
size_t len
)
virtual

Finalizes the decryption process and checks the authentication tag.

Parameters
tagThe tag value from the incoming ciphertext to be checked.
lenThe length of the tag value in bytes, which may be less than tagSize().
Returns
Returns true if the tag is identical to the first len bytes of the authentication tag that was calculated during the decryption process. Returns false otherwise.

This function must be called after the final block of ciphertext is passed to decrypt() to determine if the data could be authenticated.

Note
Authenticated cipher modes usually require that if the tag could not be verified, then all of the data that was previously decrypted must be discarded. It is unwise to use the decrypted data for any purpose before it can be verified. Callers are responsible for ensuring that any data returned via previous calls to decrypt() is discarded if checkTag() returns false.
See also
computeTag()

Implements AuthenticatedCipher.

Definition at line 150 of file ChaChaPoly.cpp.

clear()

void ChaChaPoly::clear ( )
virtual

Clears all security-sensitive state from this cipher.

Security-sensitive information includes key schedules, initialization vectors, and any temporary state that is used by encrypt() or decrypt() which is stored in the cipher itself.

Implements Cipher.

Definition at line 164 of file ChaChaPoly.cpp.

computeTag()

void ChaChaPoly::computeTag ( void * tag,
size_t len
)
virtual

Finalizes the encryption process and computes the authentication tag.

Parameters
tagPoints to the buffer to write the tag to.
lenThe length of the tag, which may be less than tagSize() to truncate the tag to the first len bytes.
See also
checkTag()

Implements AuthenticatedCipher.

Definition at line 135 of file ChaChaPoly.cpp.

decrypt()

void ChaChaPoly::decrypt ( uint8_t * output,
const uint8_t * input,
size_t len
)
virtual

Decrypts an input buffer and writes the plaintext to an output buffer.

Parameters
outputThe output buffer to write to, which may be the same buffer as input. The output buffer must have at least as many bytes as the input buffer.
inputThe input buffer to read from.
lenThe number of bytes to decrypt.

The decrypt() function can be called multiple times with different regions of the ciphertext data.

See also
encrypt()

Implements Cipher.

Definition at line 116 of file ChaChaPoly.cpp.

encrypt()

void ChaChaPoly::encrypt ( uint8_t * output,
const uint8_t * input,
size_t len
)
virtual

Encrypts an input buffer and writes the ciphertext to an output buffer.

Parameters
outputThe output buffer to write to, which may be the same buffer as input. The output buffer must have at least as many bytes as the input buffer.
inputThe input buffer to read from.
lenThe number of bytes to encrypt.

The encrypt() function can be called multiple times with different regions of the plaintext data.

See also
decrypt()

Implements Cipher.

Definition at line 105 of file ChaChaPoly.cpp.

ivSize()

size_t ChaChaPoly::ivSize ( ) const
virtual

Size of the initialization vector for this cipher, in bytes.

If the cipher does not need an initialization vector, this function will return zero.

Implements Cipher.

keySize()

size_t ChaChaPoly::keySize ( ) const
virtual

Default size of the key for this cipher, in bytes.

If the cipher supports variable-sized keys, keySize() indicates the default or recommended key size. The cipher may support other key sizes.

See also
setKey(), ivSize()

Implements Cipher.

Definition at line 61 of file ChaChaPoly.cpp.

setIV()

bool ChaChaPoly::setIV ( const uint8_t * iv,
size_t len
)
virtual

Sets the initialization vector to use for future encryption and decryption operations.

Parameters
ivThe initialization vector to use.
lenThe length of the initialization vector in bytes.
Returns
Returns false if the length is not supported.

Initialization vectors should be set before the first call to encrypt() or decrypt() after a setKey() call. If the initialization vector is changed after encryption or decryption begins, then the behaviour is undefined.

Note
The IV is not encoded into the output stream by encrypt(). The caller is responsible for communicating the IV to the other party.
See also
ivSize()

Implements Cipher.

Definition at line 84 of file ChaChaPoly.cpp.

setKey()

bool ChaChaPoly::setKey ( const uint8_t * key,
size_t len
)
virtual

Sets the key to use for future encryption and decryption operations.

Parameters
keyThe key to use.
lenThe length of the key in bytes.
Returns
Returns false if the key length is not supported, or the key is somehow "weak" and unusable by this cipher.

Use clear() or the destructor to remove the key and any other sensitive data from the object once encryption or decryption is complete.

Calling setKey() resets the cipher. Any temporary data that was being retained for encrypting partial blocks will be abandoned.

See also
keySize(), clear()

Implements Cipher.

Definition at line 79 of file ChaChaPoly.cpp.

tagSize()

size_t ChaChaPoly::tagSize ( ) const
virtual

Returns the size of the authentication tag.

Returns
The size of the authentication tag in bytes.

By default this function should return the largest tag size supported by the authenticated cipher.

See also
computeTag()

Implements AuthenticatedCipher.

Definition at line 73 of file ChaChaPoly.cpp.

The documentation for this class was generated from the following files:

  • ChaChaPoly.h
  • ChaChaPoly.cpp
Arduino Cryptography Library: ChaChaPoly Class Reference (2024)
Top Articles
Google Product Designer Salary | $111K-$637K+ | Levels.fyi
How Much Do Authors Make – WordsRated
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: The Hon. Margery Christiansen

Last Updated:

Views: 5607

Rating: 5 / 5 (70 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: The Hon. Margery Christiansen

Birthday: 2000-07-07

Address: 5050 Breitenberg Knoll, New Robert, MI 45409

Phone: +2556892639372

Job: Investor Mining Engineer

Hobby: Sketching, Cosplaying, Glassblowing, Genealogy, Crocheting, Archery, Skateboarding

Introduction: My name is The Hon. Margery Christiansen, I am a bright, adorable, precious, inexpensive, gorgeous, comfortable, happy person who loves writing and wants to share my knowledge and understanding with you.