Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished Digest and mechanisms demo #11

Merged
merged 1 commit into from
Jun 24, 2020

Conversation

lundinc2
Copy link
Contributor

No description provided.

@lundinc2 lundinc2 requested a review from yuhui-zheng June 24, 2020 17:18
Copy link
Contributor

@yuhui-zheng yuhui-zheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

* demonstrates how to generate random numbers using PKCS #11.
*/
extern void vPKCS11ManagementDemo( void );
extern void vPKCS11ManagementAndRNGDemo( void );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For line 55, 61, 66, I understand that you are trying to not put none APIs into header files.

Just me... I would still put function prototypes into a header file, though it'll only be included where the functions are implemented and where the functions are called. It makes the scope clearer and safer. (Header file in examples/ folder in this case.)

The style here used is not banned by any rule as far as I know, but I agree with the first post https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152215 "the compiler will not be able to detect the inconsistency between the two translation units".

#define configPKCS11_MECHANISMS_AND_DIGESTS_DEMO 1

/*
* @brief set this macro to "1" in order to run the PKCS #11 object demo.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment provided for configPKCS11_MECHANISMS_AND_DIGESTS_DEMO and configPKCS11_OBJECT_DEMO are the same. Copy-paste issue?


/*
* @brief set this macro to "1" in order to run the PKCS #11 management demo.
* @brief set this macro to "1" in order to run the PKCS #11 management and
* random demo.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"random" --> "random number generator" maybe. I thought it runs any demo at first glance.. 😅

CK_RV xResult = CKR_OK;

CK_FUNCTION_LIST_PTR pxFunctionList = NULL;
CK_C_INITIALIZE_ARGS xInitArgs = { 0 };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether this library/demo is targeting at ANSI C. May get a warning with "{0}"

CK_ULONG ulDataLength )
{
#define BYTES_TO_DISPLAY_PER_ROW 16
char pcByteRow[ 1 + ( BYTES_TO_DISPLAY_PER_ROW * 2 ) + ( BYTES_TO_DISPLAY_PER_ROW / 2 ) ];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious about the "math", a comment would help.

configPRINTF( ( "%s, %d bytes:\r\n", pcDescription, ulDataLength ) );

/* Iterate over the bytes of the encoded public key. */
for( ; ulIndex < ulDataLength; ulIndex++ )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave ulIndex = 0 in since another developer may come in and change the value in between this line and initialization. (I know... :( )

char pcByteRow[ 1 + ( BYTES_TO_DISPLAY_PER_ROW * 2 ) + ( BYTES_TO_DISPLAY_PER_ROW / 2 ) ];
char * pcNextChar = pcByteRow;
uint32_t ulIndex = 0;
uint8_t ucByteValue = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CK_BYTE instead of uint8_t maybe?

CK_FUNCTION_LIST_PTR pxFunctionList;
CK_KEY_TYPE xKeyType = 0;
CK_ATTRIBUTE xTemplate = { 0 };
uint8_t pucEcP256AsnAndOid[] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would appreciate some comment on the key header format. If there's a quick link to wiki, that'll help.

* "management_and_rng.c" file for the demo code explaining this section
* of cryptoki.
*/
extern void prvStart( CK_SESSION_HANDLE * pxSession,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment for the extern here.

The question to "put function prototype in headers" may be how to distinguish "private" header and "shared" header if both live in the same folder. Could play with include path...

@lundinc2 lundinc2 merged commit 6954044 into FreeRTOS:master Jun 24, 2020
lundinc2 added a commit to lundinc2/FreeRTOS-Labs that referenced this pull request Sep 22, 2020
lundinc2 added a commit to lundinc2/FreeRTOS-Labs that referenced this pull request Sep 22, 2020
lundinc2 added a commit that referenced this pull request Sep 22, 2020
* Submoduled PKCS #11 repo.

* Fix build.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants