Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lib/P11Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ CK_RV P11AttrCheckValue::updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pV
case CKK_SHA3_256_HMAC:
case CKK_SHA3_384_HMAC:
case CKK_SHA3_512_HMAC:
case CKK_CHACHA20:
key.setKeyBits(keybits);
key.setBitLen(keybits.size() * 8);
checkValue = key.getKeyCheckValue();
Expand Down Expand Up @@ -1039,6 +1040,7 @@ CK_RV P11AttrValue::updateAttr(Token *token, bool isPrivate, CK_VOID_PTR pValue,
case CKK_SHA3_256_HMAC:
case CKK_SHA3_384_HMAC:
case CKK_SHA3_512_HMAC:
case CKK_CHACHA20:
key.setKeyBits(plaintext);
key.setBitLen(plaintext.size() * 8);
checkValue = key.getKeyCheckValue();
Expand Down
38 changes: 38 additions & 0 deletions src/lib/P11Objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,44 @@ bool P11GOSTSecretKeyObj::init(OSObject *inobject)
return true;
}

// Constructor
P11ChaCha20SecretKeyObj::P11ChaCha20SecretKeyObj()
{
initialized = false;
}

// Add attributes
bool P11ChaCha20SecretKeyObj::init(OSObject *inobject)
{
if (initialized) return true;
if (inobject == NULL) return false;

if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_CHACHA20) {
OSAttribute setKeyType((unsigned long)CKK_CHACHA20);
inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
}

// Create parent
if (!P11SecretKeyObj::init(inobject)) return false;

// ChaCha20 keys always have a fixed 256-bit length; no CKA_VALUE_LEN
P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck7);

// Initialize the attributes
if (!attrValue->init())
{
ERROR_MSG("Could not initialize the attribute");
delete attrValue;
return false;
}

// Add them to the map
attributes[attrValue->getType()] = attrValue;

initialized = true;
return true;
}

// Constructor
P11DomainObj::P11DomainObj()
{
Expand Down
13 changes: 13 additions & 0 deletions src/lib/P11Objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,19 @@ class P11GOSTSecretKeyObj : public P11SecretKeyObj
bool initialized;
};

class P11ChaCha20SecretKeyObj : public P11SecretKeyObj
{
public:
// Constructor
P11ChaCha20SecretKeyObj();

// Add attributes
virtual bool init(OSObject *inobject);

protected:
bool initialized;
};

class P11DomainObj : public P11Object
{
protected:
Expand Down
Loading
Loading