Skip to content

Commit

Permalink
SE050: remove empty spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
pennam committed Oct 22, 2024
1 parent b1b9886 commit 8b7768f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
30 changes: 15 additions & 15 deletions libraries/SE05X/src/SE05X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ int SE05XClass::random(byte data[], size_t length)
smStatus_t status;
uint16_t offset = 0;
uint16_t left = length;

while (left > 0) {
uint16_t chunk = (left > SE05X_MAX_CHUNK_SIZE) ? SE05X_MAX_CHUNK_SIZE : left;
size_t max_buffer = chunk;

status = Se05x_API_GetRandom(&_se05x_session, chunk, (data + offset), &max_buffer);
if (status != SM_OK) {
SMLOG_E("Error in Se05x_API_GetRandom \n");
Expand Down Expand Up @@ -344,7 +344,7 @@ int SE05XClass::beginSHA256()
{
smStatus_t status;
SE05x_CryptoModeSubType_t subtype;

subtype.digest = kSE05x_DigestMode_SHA256;

status = Se05x_API_CreateCryptoObject(&_se05x_session, kSE05x_CryptoObject_DIGEST_SHA256, kSE05x_CryptoContext_DIGEST, subtype);
Expand All @@ -364,7 +364,7 @@ int SE05XClass::beginSHA256()
int SE05XClass::updateSHA256(const byte in[], size_t inLen)
{
smStatus_t status;

status = Se05x_API_DigestUpdate(&_se05x_session, kSE05x_CryptoObject_DIGEST_SHA256, in, inLen);
if (status != SM_OK) {
SMLOG_E("Error in Se05x_API_DigestUpdate \n");
Expand All @@ -381,7 +381,7 @@ int SE05XClass::endSHA256(byte out[], size_t* outLen)
if (*outLen < SE05X_SHA256_LENGTH) {
SMLOG_E("Error in endSHA256 \n");
*outLen = 0;
return 0;
return 0;
}

status = Se05x_API_DigestFinal(&_se05x_session, kSE05x_CryptoObject_DIGEST_SHA256, NULL, 0, out, outLen);
Expand Down Expand Up @@ -537,7 +537,7 @@ int SE05XClass::ecdsaVerify(const byte message[], const byte signature[], const
}

if (!deleteBinaryObject(SE05X_TEMP_OBJECT)) {
SMLOG_E("ecdsaVerify failure deleting temporary object\n");
SMLOG_E("ecdsaVerify failure deleting temporary object\n");
return 0;
}

Expand Down Expand Up @@ -581,7 +581,7 @@ int SE05XClass::readBinaryObject(int objectId, byte data[], size_t dataMaxLen, s
while (left > 0) {
uint16_t chunk = (left > SE05X_MAX_CHUNK_SIZE) ? SE05X_MAX_CHUNK_SIZE : left;
size_t max_buffer = chunk;

status = Se05x_API_ReadObject(&_se05x_session, objectId, offset, chunk, (data + offset), &max_buffer);
if (status != SM_OK) {
SMLOG_E("Error in Se05x_API_ReadObject \n");
Expand Down Expand Up @@ -783,9 +783,9 @@ int SE05XClass::getECKeyXyValuesFromDER(byte* derKey, size_t derLen, byte* rawKe
if(*rawLen < SE05X_EC_KEY_RAW_LENGTH) {
SMLOG_E("Error in getECKeyXyValuesFromDER \n");
*rawLen = 0;
return 0;
return 0;
}

/* XY values are stored in the last 64 bytes of DER buffer */
*rawLen = SE05X_EC_KEY_RAW_LENGTH;
memcpy(rawKey, &derKey[derLen - SE05X_EC_KEY_RAW_LENGTH], SE05X_EC_KEY_RAW_LENGTH);
Expand All @@ -798,15 +798,15 @@ int SE05XClass::setECKeyXyVauesInDER(const byte* rawKey, size_t rawLen, byte* de
if(rawLen != SE05X_EC_KEY_RAW_LENGTH) {
SMLOG_E("Error in setECKeyXyVauesInDER invalid raw key\n");
*derLen = 0;
return 0;
return 0;
}

if(*derLen < SE05X_EC_KEY_DER_LENGTH) {
SMLOG_E("Error in setECKeyXyVauesInDER buffer too small\n");
*derLen = 0;
return 0;
return 0;
}

/* Copy header byte from 0 to 25 */
memcpy(&derKey[0], &ecc_der_header_nist256[0], SE05X_EC_KEY_DER_HEADER_LENGTH);
/* Add format byte */
Expand All @@ -826,13 +826,13 @@ int SE05XClass::getECSignatureRsValuesFromDER(byte* derSignature, size_t derLen,
if ((derLen < SE05X_EC_SIGNATURE_MIN_DER_LENGTH) || (derLen > SE05X_EC_SIGNATURE_MAX_DER_LENGTH)) {
SMLOG_E("Error in getECSignatureRsValuesFromDER invalid signature\n");
*rawLen = 0;
return 0;
return 0;
}

if (*rawLen < SE05X_EC_SIGNATURE_RAW_LENGTH) {
SMLOG_E("Error in getECSignatureRsValuesFromDER buffer too small\n");
*rawLen = 0;
return 0;
return 0;
}

rLen = derSignature[3];
Expand Down Expand Up @@ -867,7 +867,7 @@ int SE05XClass::setECSignatureRsValuesInDER(const byte* rawSignature, size_t raw
{
/**
* Always consider worst case with padding
*
*
* | 0x30 0x46 0x02 0x21 0x00 | R values 32 bytes | 0x02 0x21 0x00 | S values 32 bytes |
*
*/
Expand Down
56 changes: 28 additions & 28 deletions libraries/SE05X/src/SE05X.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class SE05XClass
* @return 0 on Failure 1 on Success
*/
int generatePrivateKey(int keyID, byte keyBuf[], size_t keyBufMaxLen, size_t* keyLen);

/** generatePublicKey
*
* Reads ECCurve_NIST_P256 public key from KeyID. Public key will be available
Expand Down Expand Up @@ -117,7 +117,7 @@ class SE05XClass
* @param[in] inLen Input data length
*
* @return 0 on Failure 1 on Success
*/
*/
int updateSHA256(const byte in[], size_t inLen);

/** endSHA256
Expand All @@ -128,9 +128,9 @@ class SE05XClass
* @param[in,out] outLen Size of output data buffer, SHA256 length
*
* @return 0 on Failure 1 on Success
*/
*/
int endSHA256(byte out[], size_t* outLen);

/** SHA256
*
* One-shot SHA256
Expand All @@ -142,15 +142,15 @@ class SE05XClass
* @param[out] outLen SHA256 length
*
* @return 0 on Failure 1 on Success
*/
*/
int SHA256(const byte in[], size_t inLen, byte out[], size_t outMaxLen, size_t* outLen);

/** Sign
*
* Computes ECDSA signature using key stored in KeyID SE050 object.
* Output buffer is filled with the signature in DER format:
*
* | 0x30 | payloadsize 1 byte | 0x02 | R length 1 byte | padding 0x00 (if length 0x21) | R values 32 bytes
*
* | 0x30 | payloadsize 1 byte | 0x02 | R length 1 byte | padding 0x00 (if length 0x21) | R values 32 bytes
* | 0x02 | S length 1 byte | padding 0x00 (if length 0x21) | S values 32 bytes
*
* SHA256 -> private Key -> Signature
Expand All @@ -163,7 +163,7 @@ class SE05XClass
* @param[out] sigLen signature length
*
* @return 0 on Failure 1 on Success
*/
*/
int Sign(int keyID, const byte hash[], size_t hashLen, byte sig[], size_t maxSigLen, size_t* sigLen);

/** Verify
Expand All @@ -173,28 +173,28 @@ class SE05XClass
* Input SHA256
* ? Match ?
* Signature -> public Key -> Original SHA256
*
*
* @param[in] keyID SE050 object ID containing the key
* @param[in] hash Input SHA256 used to compute the signature
* @param[in] hashLen SHA256 length
* @param[in] sig Input buffer containint the signature
* @param[in] sigLen signature length
*
* @return 0 on Failure (Not match) 1 on Success (Match)
*/
*/
int Verify(int keyID, const byte hash[], size_t hashLen, const byte sig[],size_t sigLen);

/** readBinaryObject
*
* Reads binary data from SE050 object.
*
*
* @param[in] ObjectId SE050 object ID containing data
* @param[out] data Output data buffer
* @param[in] dataMaxLen Output data buffer size
* @param[out] sig Binary object size
*
* @return 0 on Failure 1 on Success
*/
*/
int readBinaryObject(int ObjectId, byte data[], size_t dataMaxLen, size_t* length);

/** AES_ECB_encrypt
Expand Down Expand Up @@ -268,43 +268,43 @@ class SE05XClass
/** writeBinaryObject
*
* Writes binary data into SE050 object.
*
*
* @param[in] ObjectId SE050 object ID
* @param[in] data Input data buffer
* @param[in] length Input data buffer size
*
* @return 0 on Failure 1 on Success
*/
*/
int writeBinaryObject(int ObjectId, const byte data[], size_t length);

/** existsBinaryObject
*
* Checks if Object exist
*
*
* @param[in] ObjectId SE050 object ID
*
* @return 0 on Failure (Not exist) 1 on Success (Exists)
*/
*/
int existsBinaryObject(int objectId);

/** deleteBinaryObject
*
* Deletes SE050 object
*
*
* @param[in] ObjectId SE050 object ID
*
* @return 0 on Failure 1 on Success
*/
*/
int deleteBinaryObject(int objectId);

/** deleteBinaryObject
*
* Deletes all SE050 user objects
*
*
* @param[in] ObjectId SE050 object ID
*
* @return 0 on Failure 1 on Success
*/
*/
int deleteAllObjects();

/* ECCX08 legacy API*/
Expand Down Expand Up @@ -344,20 +344,20 @@ class SE05XClass
* Input SHA256
* ? Match ?
* Signature -> public Key -> Original SHA256
*
*
* @param[in] message Input SHA256 used to compute the signature 32 bytes
* @param[in] sig Input buffer containint the signature R S values 64bytes
* @param[in] pubkey Public key X Y values 64bytes
*
* @return 0 on Failure (Not match) 1 on Success (Match)
*/
*/
int ecdsaVerify(const byte message[], const byte signature[], const byte pubkey[]);

/** ecSign
*
* Computes ECDSA signature using key stored in KeyID SE050 object.
* Output buffer is filled with the signature R S values:
*
*
* | R values 32 bytes | S values 32 bytes |
*
* SHA256 -> private Key -> Signature
Expand All @@ -367,31 +367,31 @@ class SE05XClass
* @param[out] signature Output buffer containint the signature 64 bytes
*
* @return 0 on Failure 1 on Success
*/
*/
int ecSign(int slot, const byte message[], byte signature[]);

/** readSlot
*
* Reads binary data from SE050 object.
*
*
* @param[in] ObjecslottId SE050 object ID containing data
* @param[out] data Output data buffer
* @param[in] length Number of bytes to read
*
* @return 0 on Failure 1 on Success
*/
*/
int readSlot(int slot, byte data[], int length);

/** writeSlot
*
* Writes binary data into SE050 object.
*
*
* @param[in] ObjectId SE050 object ID
* @param[in] data Input data buffer
* @param[in] length Number of bytes to write
*
* @return 0 on Failure 1 on Success
*/
*/
int writeSlot(int slot, const byte data[], int length);

inline int locked() { return 1; }
Expand Down

0 comments on commit 8b7768f

Please sign in to comment.