Google Cloud IoT device SDK for embedded C  1.0.2
iotc_bsp_crypto.h File Reference

Go to the source code of this file.

Typedefs

typedef enum iotc_bsp_crypto_state_e iotc_bsp_crypto_state_t
 

Enumerations

enum  iotc_bsp_crypto_state_e {
  IOTC_BSP_CRYPTO_STATE_OK = 0, IOTC_BSP_CRYPTO_ERROR, IOTC_BSP_CRYPTO_BASE64_ERROR, IOTC_BSP_CRYPTO_SHA256_ERROR,
  IOTC_BSP_CRYPTO_ECC_ERROR, IOTC_BSP_CRYPTO_BUFFER_TOO_SMALL_ERROR, IOTC_BSP_CRYPTO_KEY_PARSE_ERROR, IOTC_BSP_CRYPTO_SERIALIZE_ERROR,
  IOTC_BSP_CRYPTO_INVALID_INPUT_PARAMETER_ERROR
}
 

Functions

iotc_bsp_crypto_state_t iotc_bsp_base64_encode_urlsafe (unsigned char *dst_string, size_t dst_string_size, size_t *bytes_written, const uint8_t *src_buf, size_t src_buf_size)
 
iotc_bsp_crypto_state_t iotc_bsp_sha256 (uint8_t *dst_buf_32_bytes, const uint8_t *src_buf, uint32_t src_buf_size)
 
iotc_bsp_crypto_state_t iotc_bsp_ecc (const iotc_crypto_key_data_t *private_key, uint8_t *dst_buf, size_t dst_buf_size, size_t *bytes_written, const uint8_t *src_buf, size_t src_buf_size)
 

Detailed Description

Implements a cryptography library for creating JSON Web Tokens.

The cryptography library:

  • Generates JWT credentials.
  • Signs JWTs with Elliptic Curve cryptography and SHA256.
  • Encodes signed JWTs as URL-safe base64 strings.

Definition in file iotc_bsp_crypto.h.

Typedef Documentation

◆ iotc_bsp_crypto_state_t

The crytography function states.

See also
iotc_bsp_crypto_state_e

Enumeration Type Documentation

◆ iotc_bsp_crypto_state_e

Enumerator
IOTC_BSP_CRYPTO_STATE_OK 

The cryptography function succeeded.

IOTC_BSP_CRYPTO_ERROR 

Something went wrong.

IOTC_BSP_CRYPTO_BASE64_ERROR 

Can't base64-encode string.

IOTC_BSP_CRYPTO_SHA256_ERROR 

Can't create SHA256 digest.

IOTC_BSP_CRYPTO_ECC_ERROR 

Can't create ECC signature.

IOTC_BSP_CRYPTO_BUFFER_TOO_SMALL_ERROR 

Can't write data to the buffer because the data is larger than the buffer.

IOTC_BSP_CRYPTO_KEY_PARSE_ERROR 

Can't parse private key data.

IOTC_BSP_CRYPTO_SERIALIZE_ERROR 

Can't serialize data.

IOTC_BSP_CRYPTO_INVALID_INPUT_PARAMETER_ERROR 

Invalid parameter.

Definition at line 46 of file iotc_bsp_crypto.h.

Function Documentation

◆ iotc_bsp_base64_encode_urlsafe()

iotc_bsp_crypto_state_t iotc_bsp_base64_encode_urlsafe ( unsigned char *  dst_string,
size_t  dst_string_size,
size_t *  bytes_written,
const uint8_t *  src_buf,
size_t  src_buf_size 
)

Encodes a string as a URL-safe, base64 string by replacing all URL-unsafe characters with a - (dash) or _ (underscore).

Parameters
[in,out]dst_stringA pointer to a buffer that stores the URL-safe, base64 string. The SDK allocates the buffer before calling this function implementation.
[in]dst_string_sizeThe length, in bytes, of the dst_string buffer.
[out]bytes_writtenThe bytes written to dst_string. If the buffer is too small, bytes_written is the required buffer size.
[in]src_bufA pointer to a buffer with the string to encode.
[in]src_buf_sizeThe size, in bytes, of buffer to which src_buf points.
Returns
A crytography function status.

◆ iotc_bsp_ecc()

iotc_bsp_crypto_state_t iotc_bsp_ecc ( const iotc_crypto_key_data_t *  private_key,
uint8_t *  dst_buf,
size_t  dst_buf_size,
size_t *  bytes_written,
const uint8_t *  src_buf,
size_t  src_buf_size 
)

Generates an Elliptic Curve signature for a private key.

Parameters
[in]private_keyThe private key data or slot number. Implementations of this function must use the same private key data or slot number provided to iotc_create_iotcore_jwt().
[in,out]dst_bufA pointer to a buffer into which the function stores the Elliptic Curve signature. The buffer is already allocated by the SDK.
[in]dst_buf_sizeThe size, in bytes, of the buffer to which dst_buf points.
[out]bytes_writtenThe number of bytes written to dst_buf.
[in]src_bufA pointer to a buffer of data to sign.
[in]src_buf_sizeThe size, in bytes, of the buffer to which src_buf points.

◆ iotc_bsp_sha256()

iotc_bsp_crypto_state_t iotc_bsp_sha256 ( uint8_t *  dst_buf_32_bytes,
const uint8_t *  src_buf,
uint32_t  src_buf_size 
)

Generates a SHA256 cryptographic hash.

Parameters
[in,out]dst_buf_32_bytesA pointer to 32-byte buffer into which this function stores the digest. The buffer is already allocated by the SDK.
[in]src_bufA pointer to buffer with the string to encode.
[in]src_buf_sizeThe size, in bytes, of the buffer to which src_buf points.