wpa_supplicant / hostapd  2.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Functions
crypto_internal-rsa.c File Reference

Crypto wrapper for internal crypto implementation - RSA parts. More...

#include "includes.h"
#include "common.h"
#include "crypto.h"
#include "tls/rsa.h"
#include "tls/pkcs1.h"
#include "tls/pkcs8.h"

Functions

struct crypto_public_keycrypto_public_key_import (const u8 *key, size_t len)
 Import an RSA public key. More...
 
struct crypto_public_keycrypto_public_key_import_parts (const u8 *n, size_t n_len, const u8 *e, size_t e_len)
 
struct crypto_private_keycrypto_private_key_import (const u8 *key, size_t len, const char *passwd)
 Import an RSA private key. More...
 
struct crypto_public_keycrypto_public_key_from_cert (const u8 *buf, size_t len)
 Import an RSA public key from a certificate. More...
 
int crypto_public_key_encrypt_pkcs1_v15 (struct crypto_public_key *key, const u8 *in, size_t inlen, u8 *out, size_t *outlen)
 Public key encryption (PKCS #1 v1.5) More...
 
int crypto_private_key_decrypt_pkcs1_v15 (struct crypto_private_key *key, const u8 *in, size_t inlen, u8 *out, size_t *outlen)
 Private key decryption (PKCS #1 v1.5) More...
 
int crypto_private_key_sign_pkcs1 (struct crypto_private_key *key, const u8 *in, size_t inlen, u8 *out, size_t *outlen)
 Sign with private key (PKCS #1) More...
 
void crypto_public_key_free (struct crypto_public_key *key)
 Free public key. More...
 
void crypto_private_key_free (struct crypto_private_key *key)
 Free private key. More...
 
int crypto_public_key_decrypt_pkcs1 (struct crypto_public_key *key, const u8 *crypt, size_t crypt_len, u8 *plain, size_t *plain_len)
 Decrypt PKCS #1 signature. More...
 

Detailed Description

Crypto wrapper for internal crypto implementation - RSA parts.

Function Documentation

int crypto_private_key_decrypt_pkcs1_v15 ( struct crypto_private_key key,
const u8 *  in,
size_t  inlen,
u8 *  out,
size_t *  outlen 
)

Private key decryption (PKCS #1 v1.5)

Parameters
keyPrivate key
inEncrypted buffer
inlenLength of encrypted buffer in bytes
outOutput buffer for encrypted data
outlenLength of output buffer in bytes; set to used length on success
Returns
0 on success, -1 on failure

This function is only used with internal TLSv1 implementation (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need to implement this.

void crypto_private_key_free ( struct crypto_private_key key)

Free private key.

Parameters
keyPrivate key from crypto_private_key_import()

This function is only used with internal TLSv1 implementation (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need to implement this.

struct crypto_private_key* crypto_private_key_import ( const u8 *  key,
size_t  len,
const char *  passwd 
)

Import an RSA private key.

Parameters
keyKey buffer (DER encoded RSA private key)
lenKey buffer length in bytes
passwdKey encryption password or NULL if key is not encrypted
Returns
Pointer to the private key or NULL on failure

This function is only used with internal TLSv1 implementation (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need to implement this.

int crypto_private_key_sign_pkcs1 ( struct crypto_private_key key,
const u8 *  in,
size_t  inlen,
u8 *  out,
size_t *  outlen 
)

Sign with private key (PKCS #1)

Parameters
keyPrivate key from crypto_private_key_import()
inPlaintext buffer
inlenLength of plaintext buffer in bytes
outOutput buffer for encrypted (signed) data
outlenLength of output buffer in bytes; set to used length on success
Returns
0 on success, -1 on failure

This function is only used with internal TLSv1 implementation (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need to implement this.

int crypto_public_key_decrypt_pkcs1 ( struct crypto_public_key key,
const u8 *  crypt,
size_t  crypt_len,
u8 *  plain,
size_t *  plain_len 
)

Decrypt PKCS #1 signature.

Parameters
keyPublic key
cryptEncrypted signature data (using the private key)
crypt_lenEncrypted signature data length
plainBuffer for plaintext (at least crypt_len bytes)
plain_lenPlaintext length (max buffer size on input, real len on output);
Returns
0 on success, -1 on failure
int crypto_public_key_encrypt_pkcs1_v15 ( struct crypto_public_key key,
const u8 *  in,
size_t  inlen,
u8 *  out,
size_t *  outlen 
)

Public key encryption (PKCS #1 v1.5)

Parameters
keyPublic key
inPlaintext buffer
inlenLength of plaintext buffer in bytes
outOutput buffer for encrypted data
outlenLength of output buffer in bytes; set to used length on success
Returns
0 on success, -1 on failure

This function is only used with internal TLSv1 implementation (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need to implement this.

void crypto_public_key_free ( struct crypto_public_key key)

Free public key.

Parameters
keyPublic key

This function is only used with internal TLSv1 implementation (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need to implement this.

struct crypto_public_key* crypto_public_key_from_cert ( const u8 *  buf,
size_t  len 
)

Import an RSA public key from a certificate.

Parameters
bufDER encoded X.509 certificate
lenCertificate buffer length in bytes
Returns
Pointer to public key or NULL on failure

This function can just return NULL if the crypto library does not support X.509 parsing. In that case, internal code will be used to parse the certificate and public key is imported using crypto_public_key_import().

This function is only used with internal TLSv1 implementation (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need to implement this.

struct crypto_public_key* crypto_public_key_import ( const u8 *  key,
size_t  len 
)

Import an RSA public key.

Parameters
keyKey buffer (DER encoded RSA public key)
lenKey buffer length in bytes
Returns
Pointer to the public key or NULL on failure

This function can just return NULL if the crypto library supports X.509 parsing. In that case, crypto_public_key_from_cert() is used to import the public key from a certificate.

This function is only used with internal TLSv1 implementation (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need to implement this.