/home/dko/projects/mobilec/tags/MobileC-v1.10.2/MobileC-v1.10.2/src/security/xyssl-0.9/include/xyssl/rsa.h File Reference

#include "xyssl/bignum.h"

Go to the source code of this file.

Data Structures

struct  rsa_context
 RSA context structure. More...

Defines

#define XYSSL_ERR_RSA_BAD_INPUT_DATA   -0x0400
#define XYSSL_ERR_RSA_INVALID_PADDING   -0x0410
#define XYSSL_ERR_RSA_KEY_GEN_FAILED   -0x0420
#define XYSSL_ERR_RSA_KEY_CHECK_FAILED   -0x0430
#define XYSSL_ERR_RSA_PUBLIC_FAILED   -0x0440
#define XYSSL_ERR_RSA_PRIVATE_FAILED   -0x0450
#define XYSSL_ERR_RSA_VERIFY_FAILED   -0x0460
#define RSA_RAW   0
#define RSA_MD2   2
#define RSA_MD4   3
#define RSA_MD5   4
#define RSA_SHA1   5
#define RSA_SHA256   6
#define RSA_PUBLIC   0
#define RSA_PRIVATE   1
#define RSA_PKCS_V15   0
#define RSA_PKCS_V21   1
#define RSA_SIGN   1
#define RSA_CRYPT   2
#define ASN1_HASH_MDX
#define ASN1_HASH_SHA1

Functions

void rsa_init (rsa_context *ctx, int padding, int hash_id, int(*f_rng)(void *), void *p_rng)
 Initialize an RSA context.
int rsa_gen_key (rsa_context *ctx, int nbits, int exponent)
 Generate an RSA keypair.
int rsa_check_pubkey (rsa_context *ctx)
 Check a public RSA key.
int rsa_check_privkey (rsa_context *ctx)
 Check a private RSA key.
int rsa_public (rsa_context *ctx, unsigned char *input, unsigned char *output)
 Do an RSA public key operation.
int rsa_private (rsa_context *ctx, unsigned char *input, unsigned char *output)
 Do an RSA private key operation.
int rsa_pkcs1_encrypt (rsa_context *ctx, int mode, int ilen, unsigned char *input, unsigned char *output)
 Add the message padding, then do an RSA operation.
int rsa_pkcs1_decrypt (rsa_context *ctx, int mode, int *olen, unsigned char *input, unsigned char *output)
 Do an RSA operation, then remove the message padding.
int rsa_pkcs1_sign (rsa_context *ctx, int mode, int hash_id, int hashlen, unsigned char *hash, unsigned char *sig)
 Do a private RSA to sign a message digest.
int rsa_pkcs1_verify (rsa_context *ctx, int mode, int hash_id, int hashlen, unsigned char *hash, unsigned char *sig)
 Do a public RSA and check the message digest.
void rsa_free (rsa_context *ctx)
 Free the components of an RSA key.
int rsa_self_test (int verbose)
 Checkup routine.


Detailed Description

Definition in file rsa.h.


Define Documentation

#define ASN1_HASH_MDX

Value:

"\x30\x20\x30\x0C\x06\x08\x2A\x86\x48"  \
    "\x86\xF7\x0D\x02\x00\x05\x00\x04\x10"

Definition at line 45 of file rsa.h.

#define ASN1_HASH_SHA1

Value:

"\x30\x21\x30\x09\x06\x05\x2B\x0E\x03"  \
    "\x02\x1A\x05\x00\x04\x14"

Definition at line 49 of file rsa.h.

#define RSA_CRYPT   2

Definition at line 34 of file rsa.h.

#define RSA_MD2   2

Definition at line 21 of file rsa.h.

#define RSA_MD4   3

Definition at line 22 of file rsa.h.

#define RSA_MD5   4

Definition at line 23 of file rsa.h.

#define RSA_PKCS_V15   0

Definition at line 30 of file rsa.h.

Referenced by main().

#define RSA_PKCS_V21   1

Definition at line 31 of file rsa.h.

#define RSA_PRIVATE   1

Definition at line 28 of file rsa.h.

Referenced by main(), RSA_private_decrypt(), and RSA_private_encrypt().

#define RSA_PUBLIC   0

Definition at line 27 of file rsa.h.

Referenced by main(), RSA_public_decrypt(), and RSA_public_encrypt().

#define RSA_RAW   0

Definition at line 20 of file rsa.h.

#define RSA_SHA1   5

Definition at line 24 of file rsa.h.

Referenced by main().

#define RSA_SHA256   6

Definition at line 25 of file rsa.h.

#define RSA_SIGN   1

Definition at line 33 of file rsa.h.

#define XYSSL_ERR_RSA_BAD_INPUT_DATA   -0x0400

Definition at line 9 of file rsa.h.

#define XYSSL_ERR_RSA_INVALID_PADDING   -0x0410

Definition at line 10UQjɸm!&-卢<(6仌Ұg2sK#s Gr0+{SǵV}['jL=K!&\47pd ȓU7ϑJViw Ց0w e5hc5{htͯhu0RdRۡr$3`O@) v#0n#Ewtӎ#†#-sՅ ]G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R>w/.҃.\Z;9ـ%8J=¢'Xr(r6l0TSS@+6klz$_)&@1uLy"pacJ˫"-~$7/~%mB2s<.ץ\x3y&"BAXzYk{ u s gIcM|Evri28tf0~&W ^ q5D!='.uF0WgXoX#C7Ӽ=Q:)5Uu۠ S "| [vTm,'v5үG1Iem(eG&8}M^ rbSvdz(B^(dolW;Ԫ/s 66jio]}J8ٌ5_sZl71cz chMgH_}) -{UʵhNkYϹ\2*rTz7c,h0T?J*B/̔G~` Mkp㎉:.;6P #G (m0" tJ CHІL=9ϕ6;N(Vp>zc9 ,N4MCy1 ʅ5Uڌr9Mf傥 s @tB4_(9fRʣtqz8DD0,}oZױ>ۍQ:]B9'(oOj?%-+C{8u1lEGɃ je̸u9$ҩ*)}e{3rk 1yIWOijjl,ns\PL^^ќ'M`$\0_LS^WAba>$>= ѡ?#۷MNs"S>溟9S-#>0.g%:Nwu Asc&{ yNIPD8_n Yg). awyg/T1+jՃ&'>U%.̄['&Bk d@(x\c f-}03+#.\{}vMykv;j8[W&TҝT >RL(1Հ奴9sLrf~ާCINUu9 r=jmϬ7RW[[՝˼ O0` ({v m~xWW̐!e3gU7y/@jjMsnivsGDW/UM 5YZղ\rEɉf,2JnuJ)0ɘ'L{KmЦ#Ƥ [~=hlbT?Dm@ |F~zG,H9pfnz@Z-7lCxk\(~Eo o2] 2߻cqY=<,6CEMܺ(=+"T8⩊ui?p+Gn0䊩L.Li:*Y!.ijq4>Eh;ۘ4SFT󬦟\C?:: ,ԁ5q#K0xN۱ꁇIBa*A)PN4_kOR(+e,.Q{I i8fUgdW1[jPlzCJG|{F]YH[tQTka9cFo+1Tubr DsI +(nJ7<Ͼssey'sH-1/^3CamrtEo setup the RSA context (especially f_rng and p_rng).

Returns:
0 if successful, or an XYSSL_ERR_RSA_XXX error code

Referenced by main().

void rsa_init ( rsa_context ctx,
int  padding,
int  hash_id,
int(*)(void *)  f_rng,
void *  p_rng 
)

Initialize an RSA context.

Parameters:
ctx RSA context to be initialized
padding RSA_PKCS_V15 or RSA_PKCS_V21
hash_id RSA_PKCS_V21 hash identifier
f_rng RNG function
p_rng RNG parameter
Note:
The hash_id parameter is actually ignored when using RSA_PKCS_V15 padding.

Currently (xyssl-0.8), RSA_PKCS_V21 padding is not supported.

Referenced by main().

int rsa_pkcs1_decrypt ( rsa_context ctx,
int  mode,
int rsa_check_pubkey ( rsa_context ctx  ) 

Check a public RSA key.

Parameters:
ctx RSA context to be checked
Returns:
0 if successful, or an XYSSL_ERR_RSA_XXX error code

void rsa_free ( rsa_context ctx  ) 

Free the components of an RSA key.

Referenced by main(), and ssl_test().

int rsa_gen_key ( rsa_context ctx,
int  nbits,
int  exponent 
)

Generate an RSA keypair.

Parameters:
ctx RSA context that will hold the key
nbits size of the public key in bits
exponent public exponent (e.g., 65537)
Note:
rsa_init() must be called beforehand tIC or RSA_PRIVATE
ilen contains the the plaintext length
input buffer holding the data to be encrypted
output buffer that will hold the ciphertext
Returns:
0 if successful, or an XYSSL_ERR_RSA_XXX error code
Note:
The output buffer must be as large as the size of ctx->N (eg. 128 bytes if RSA-1024 is used).

Referenced by RSA_private_encrypt(), and RSA_public_encrypt().

int rsa_pkcs1_sign ( rsa_context ctx,
int  mode,
int  hash_id,
int  hashlen,
unsigned char *  hash,
unsigned char *  sig 
)

Do a private RSA to sign a message digest.

Parameters:
ctx RSA context
mode RSA_PUBLIC or RSA_PRIVATE
hash_id RSA_RAW, RSA_MD{2,4,5} or RSA_SHA{1,256}
hashlen message digest length (for RSA_RAW only)
hash buffer holding the message digest
sig buffer that will hold the ciphertext
Returns:
0 if the signing operation was successful, or an XYSSL_ERR_RSA_XXX error code
Note:
The "sig" buffer must be as large as the size of ctx->N (eg. 128 bytes if RSA-1024 is used).

Referenced by main().

int rsa_pkcs1_verify ( rsa_context ctx,
int  mode,
int  hash_id,
int  hashlen,
unsigned char *  hash,
unsigned char *  sig 
)

Do a public RSA and check the message digest.

Parameters:
ctx points to an RSA public key
mode RSA_PUBLIC or RSA_PRIVATE
hash_id RSA_RAW, RSA_MD{2,4,5} or RSA_SHA{1,256}
hashlen message digest length (for RSA_RAW only)
hash buffer holding the message digest
sig buffer holding the ciphertext
Returns:
0 if the verify operation was successful, or an XYSSL_ERR_RSA_XXX error code
Note:
The "sig" buffer must be as large as the size of ctx->N (eg. 128 bytes if RSA-1024 is used).

Referenced by main().

int rsa_private ( rsa_context ctx,
unsigned char *  input,
unsigned char *  output 
)

Do an RSA private key operation.

Parameters:
ctx RSA context
input input buffer
output output buffer
Returns:
0 if successful, or an XYSSL_ERR_RSA_XXX error code
Note:
The input and output buffers must be large enough (eg. 128 bytes if RSA-1024 is used).

Referenced by main().

int rsa_public ( rsa_context ctx,
unsigned char *  input,
unsigned char *  output 
)

Do an RSA public key operation.

Parameters:
ctx RSA context
input input buffer
output output buffer
Returns:
0 if successful, or an XYSSL_ERR_RSA_XXX error code
Note:
This function does NOT take care of message padding. Also, be sure to set input[0] = 0.

The input and output buffers must be large enough (eg. 128 bytes if RSA-1024 is used).

Referenced by main().

int rsa_self_test ( int  verbose  ) 

Checkup routine.

Returns:
0 if successful, or 1 if the test failed

Referenced by main().


Generated on Fri Jul 11 17:59:48 2008 for Mobile-C by  doxygen 1.5.4