LibJWT 3.4.0
The C JSON Web Token Library +JWK +JWKS
Algorithms

Convert between algorithm types and their string names. More...

Collaboration diagram for Algorithms:

Enumerations

enum  jwt_alg_t {
  JWT_ALG_NONE = 0 , JWT_ALG_HS256 , JWT_ALG_HS384 , JWT_ALG_HS512 ,
  JWT_ALG_RS256 , JWT_ALG_RS384 , JWT_ALG_RS512 , JWT_ALG_ES256 ,
  JWT_ALG_ES384 , JWT_ALG_ES512 , JWT_ALG_PS256 , JWT_ALG_PS384 ,
  JWT_ALG_PS512 , JWT_ALG_ES256K , JWT_ALG_EDDSA , JWT_ALG_ML_DSA_44 ,
  JWT_ALG_ML_DSA_65 , JWT_ALG_ML_DSA_87 , JWT_ALG_INVAL
}
 JWT algorithm types. More...
enum  jwe_key_alg_t {
  JWE_ALG_NONE = 0 , JWE_ALG_DIR , JWE_ALG_A128KW , JWE_ALG_A192KW ,
  JWE_ALG_A256KW , JWE_ALG_RSA_OAEP , JWE_ALG_RSA_OAEP_256 , JWE_ALG_ECDH_ES ,
  JWE_ALG_ECDH_ES_A128KW , JWE_ALG_ECDH_ES_A192KW , JWE_ALG_ECDH_ES_A256KW , JWE_ALG_INVAL
}
 JWE key management algorithm types. More...
enum  jwe_enc_t {
  JWE_ENC_NONE = 0 , JWE_ENC_A128GCM , JWE_ENC_A192GCM , JWE_ENC_A256GCM ,
  JWE_ENC_A128CBC_HS256 , JWE_ENC_A192CBC_HS384 , JWE_ENC_A256CBC_HS512 , JWE_ENC_INVAL
}
 JWE content encryption algorithm types. More...
enum  jwe_serialization_t { JWE_FORMAT_COMPACT = 0 , JWE_FORMAT_JSON_FLAT , JWE_FORMAT_JSON_GENERAL }
 JWE serialization formats. More...

Functions

jwt_alg_t jwt_get_alg (const jwt_t *jwt)
const char * jwt_alg_str (jwt_alg_t alg)
jwt_alg_t jwt_str_alg (const char *alg)
const char * jwe_alg_str (jwe_key_alg_t alg)
jwe_key_alg_t jwe_str_alg (const char *alg)
const char * jwe_enc_str (jwe_enc_t enc)
jwe_enc_t jwe_str_enc (const char *enc)

Detailed Description

Convert between algorithm types and their string names.

Utility functions to convert between string and type for alg

Enumeration Type Documentation

◆ jwe_enc_t

enum jwe_enc_t

JWE content encryption algorithm types.

These are the supported JWE "enc" (content encryption) algorithm types for LibJWT. They determine the authenticated encryption applied to the plaintext using the CEK.

RFC-7518 Sec 5.1

Enumerator
JWE_ENC_NONE 

No/unset content encryption algorithm

JWE_ENC_A128GCM 

AES GCM using 128-bit key

JWE_ENC_A192GCM 

AES GCM using 192-bit key

JWE_ENC_A256GCM 

AES GCM using 256-bit key

JWE_ENC_A128CBC_HS256 

AES 128 CBC + HMAC SHA-256 (truncated)

JWE_ENC_A192CBC_HS384 

AES 192 CBC + HMAC SHA-384 (truncated)

JWE_ENC_A256CBC_HS512 

AES 256 CBC + HMAC SHA-512 (truncated)

JWE_ENC_INVAL 

An invalid algorithm from the caller or the token

◆ jwe_key_alg_t

JWE key management algorithm types.

These are the supported JWE "alg" (key management) algorithm types for LibJWT. They determine how the Content Encryption Key (CEK) is produced for or recovered from a recipient. They are intentionally a separate type from jwt_alg_t (which is JWS/signing only); the "alg" values used in JWE and JWS are not the same.

RFC-7518 Sec 4.1

Enumerator
JWE_ALG_NONE 

No/unset key management algorithm

JWE_ALG_DIR 

Direct use of a shared symmetric key as the CEK

JWE_ALG_A128KW 

AES Key Wrap with 128-bit key

JWE_ALG_A192KW 

AES Key Wrap with 192-bit key

JWE_ALG_A256KW 

AES Key Wrap with 256-bit key

JWE_ALG_RSA_OAEP 

RSAES-OAEP using default (SHA-1) parameters

JWE_ALG_RSA_OAEP_256 

RSAES-OAEP using SHA-256 and MGF1 with SHA-256

JWE_ALG_ECDH_ES 

ECDH-ES using Concat KDF (Direct Key Agreement)

JWE_ALG_ECDH_ES_A128KW 

ECDH-ES using Concat KDF and CEK wrapped with A128KW

JWE_ALG_ECDH_ES_A192KW 

ECDH-ES using Concat KDF and CEK wrapped with A192KW

JWE_ALG_ECDH_ES_A256KW 

ECDH-ES using Concat KDF and CEK wrapped with A256KW

JWE_ALG_INVAL 

An invalid algorithm from the caller or the token

◆ jwe_serialization_t

JWE serialization formats.

RFC 7516 defines two serializations. The Compact Serialization is the five-part header.encrypted_key.iv.ciphertext.tag string and supports a single recipient. The JSON Serialization is a JSON object; its Flattened form is the single-recipient special case, and its General form carries a recipients array for one or more recipients.

RFC-7516 Sec 7

Enumerator
JWE_FORMAT_COMPACT 

RFC-7516 Sec 7.1 Compact Serialization (default)

JWE_FORMAT_JSON_FLAT 

RFC-7516 Sec 7.2.2 Flattened JSON Serialization

JWE_FORMAT_JSON_GENERAL 

RFC-7516 Sec 7.2.1 General JSON Serialization

◆ jwt_alg_t

enum jwt_alg_t

JWT algorithm types.

These are the supported algorithm types for LibJWT.

RFC-7518 Sec 3.1

Enumerator
JWT_ALG_NONE 

No signature

JWT_ALG_HS256 

HMAC using SHA-256

JWT_ALG_HS384 

HMAC using SHA-384

JWT_ALG_HS512 

HMAC using SHA-512

JWT_ALG_RS256 

RSASSA-PKCS1-v1_5 using SHA-256

JWT_ALG_RS384 

RSASSA-PKCS1-v1_5 using SHA-384

JWT_ALG_RS512 

RSASSA-PKCS1-v1_5 using SHA-512

JWT_ALG_ES256 

ECDSA using P-256 and SHA-256

JWT_ALG_ES384 

ECDSA using P-384 and SHA-384

JWT_ALG_ES512 

ECDSA using P-521 and SHA-512

JWT_ALG_PS256 

RSASSA-PSS using SHA-256 and MGF1 with SHA-256

JWT_ALG_PS384 

RSASSA-PSS using SHA-384 and MGF1 with SHA-384

JWT_ALG_PS512 

RSASSA-PSS using SHA-512 and MGF1 with SHA-512

JWT_ALG_ES256K 

ECDSA using secp256k1 and SHA-256

JWT_ALG_EDDSA 

EdDSA using Ed25519

JWT_ALG_ML_DSA_44 

ML-DSA-44 (FIPS 204, RFC 9964) (experimental)

JWT_ALG_ML_DSA_65 

ML-DSA-65 (FIPS 204, RFC 9964) (experimental)

JWT_ALG_ML_DSA_87 

ML-DSA-87 (FIPS 204, RFC 9964) (experimental)

JWT_ALG_INVAL 

An invalid algorithm from the caller or the token

Function Documentation

◆ jwe_alg_str()

const char * jwe_alg_str ( jwe_key_alg_t alg)

Convert a JWE key management alg type to its string representation.

Parameters
algA valid jwe_key_alg_t specifier.
Returns
Returns a string (e.g. "RSA-OAEP") matching the alg or NULL for an invalid alg.

◆ jwe_enc_str()

const char * jwe_enc_str ( jwe_enc_t enc)

Convert a JWE content encryption enc type to its string representation.

Parameters
encA valid jwe_enc_t specifier.
Returns
Returns a string (e.g. "A256GCM") matching the enc or NULL for an invalid enc.

◆ jwe_str_alg()

jwe_key_alg_t jwe_str_alg ( const char * alg)

Convert a JWE key management alg string to type.

RFC-7518 Sec 4.1

Parameters
algA valid string for a JWE key management algorithm (e.g. "A128KW").
Returns
Returns a jwe_key_alg_t matching the string or JWE_ALG_INVAL if no matches were found.

◆ jwe_str_enc()

jwe_enc_t jwe_str_enc ( const char * enc)

Convert a JWE content encryption enc string to type.

RFC-7518 Sec 5.1

Parameters
encA valid string for a JWE content encryption algorithm (e.g. "A256GCM").
Returns
Returns a jwe_enc_t matching the string or JWE_ENC_INVAL if no matches were found.

◆ jwt_alg_str()

const char * jwt_alg_str ( jwt_alg_t alg)

Convert alg type to it's string representation.

Returns a string that matches the alg type provided.

Parameters
algA valid jwt_alg_t specifier.
Returns
Returns a string (e.g. "RS256") matching the alg or NULL for invalid alg.

◆ jwt_get_alg()

jwt_alg_t jwt_get_alg ( const jwt_t * jwt)

Get the jwt_alg_t set for this JWT object.

Returns the jwt_alg_t type for this JWT object.

Parameters
jwtPointer to a JWT object.
Returns
Returns a jwt_alg_t type for this object.

◆ jwt_str_alg()

jwt_alg_t jwt_str_alg ( const char * alg)

Convert alg string to type.

Returns an alg type based on the string representation.

RFC-7518 Sec 3.1

Parameters
algA valid string for algorithm type (e.g. "RS256").
Returns
Returns a jwt_alg_t matching the string or JWT_ALG_INVAL if no matches were found.
Note
This only works for algorithms that LibJWT supports or knows about.