Skip to content

Commit

Permalink
Restore compatibility with wolfPKCS11_Store_Open and add new API `w…
Browse files Browse the repository at this point in the history
…olfPKCS11_Store_OpenSz` to support the new variable size argument (only required for use with TPM's).
  • Loading branch information
dgarske committed Jan 2, 2025
1 parent b96cdfb commit b4466aa
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
24 changes: 21 additions & 3 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ static int wolfPKCS11_Store_GetMaxSize(int type, int variableSz)
* @return NOT_AVAILABLE_E when data not available.
* @return Other value to indicate failure.
*/
int wolfPKCS11_Store_Open(int type, CK_ULONG id1, CK_ULONG id2, int read,
int wolfPKCS11_Store_OpenSz(int type, CK_ULONG id1, CK_ULONG id2, int read,
int variableSz, void** store)
{
int ret = 0;
Expand Down Expand Up @@ -908,6 +908,24 @@ int wolfPKCS11_Store_Open(int type, CK_ULONG id1, CK_ULONG id2, int read,
return ret;
}

/**
* Opens access to location to read/write token data.
*
* @param [in] type Type of data to be stored. See WOLFPKCS11_STORE_*.
* @param [in] id1 Numeric identifier 1.
* @param [in] id2 Numeric identifier 2.
* @param [in] read 1 when opening for read and 0 for write.
* @param [out] store Returns file pointer.
* @return 0 on success.
* @return NOT_AVAILABLE_E when data not available.
* @return Other value to indicate failure.
*/
int wolfPKCS11_Store_Open(int type, CK_ULONG id1, CK_ULONG id2, int read,
void** store)
{
return wolfPKCS11_Store_OpenSz(type, id1, id2, read, 0, store);
}

/**
* Closes access to location being read or written.
* Any dynamic memory associated with the store is freed here.
Expand Down Expand Up @@ -1037,7 +1055,7 @@ int wolfPKCS11_Store_Write(void* store, unsigned char* buffer, int len)
static int wp11_storage_open_readonly(int type, CK_ULONG id1, CK_ULONG id2,
void** storage)
{
return wolfPKCS11_Store_Open(type, id1, id2, 1, 0, storage);
return wolfPKCS11_Store_OpenSz(type, id1, id2, 1, 0, storage);
}

/*
Expand All @@ -1055,7 +1073,7 @@ static int wp11_storage_open_readonly(int type, CK_ULONG id1, CK_ULONG id2,
static int wp11_storage_open(int type, CK_ULONG id1, CK_ULONG id2,
int variableSz, void** storage)
{
return wolfPKCS11_Store_Open(type, id1, id2, 0, variableSz, storage);
return wolfPKCS11_Store_OpenSz(type, id1, id2, 0, variableSz, storage);
}

/*
Expand Down
17 changes: 16 additions & 1 deletion wolfpkcs11/store.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,28 @@
* @param [in] id1 Numeric identifier 1.
* @param [in] id2 Numeric identifier 2.
* @param [in] read 1 when opening for read and 0 for write.
* @param [in] variableSz additional size needed for type (needed on write)
* @param [out] store Return pointer to context data.
* @return 0 on success.
* @return -4 when data not available.
* @return Other value to indicate failure.
*/
int wolfPKCS11_Store_Open(int type, CK_ULONG id1, CK_ULONG id2, int read,
void** store);

/*
* Opens access to location to read/write token data.
*
* @param [in] type Type of data to be stored. See WOLFPKCS11_STORE_* above.
* @param [in] id1 Numeric identifier 1.
* @param [in] id2 Numeric identifier 2.
* @param [in] read 1 when opening for read and 0 for write.
* @param [in] variableSz additional size needed for type (needed on write)
* @param [out] store Return pointer to context data.
* @return 0 on success.
* @return -4 when data not available.
* @return Other value to indicate failure.
*/
int wolfPKCS11_Store_OpenSz(int type, CK_ULONG id1, CK_ULONG id2, int read,
int variableSz, void** store);

/*
Expand Down

0 comments on commit b4466aa

Please sign in to comment.