# Utils Library

## Data Structures

struct | _SceKernelUtilsMt19937Context
| Structure for holding a mersenne twister context. More...
struct | _SceKernelUtilsMd5Context
| Structure to hold the MD5 context. More...
struct | _SceKernelUtilsSha1Context
| Type to hold a sha1 context. More...

## Typedefs

typedef _SceKernelUtilsMt19937Context | SceKernelUtilsMt19937Context
| Structure for holding a mersenne twister context.
typedef _SceKernelUtilsMd5Context | SceKernelUtilsMd5Context
| Structure to hold the MD5 context.
typedef _SceKernelUtilsSha1Context | SceKernelUtilsSha1Context
| Type to hold a sha1 context.

## Functions

time_t | sceKernelLibcTime (time_t *t)
| Get the time in seconds since the epoc (1st Jan 1970).
clock_t | sceKernelLibcClock (void)
| Get the processor clock used since the start of the process.
int | sceKernelLibcGettimeofday (struct timeval *tp, struct timezone *tzp)
| Get the current time of time and time zone information.
void | sceKernelDcacheWritebackAll (void)
| Write back the data cache to memory.
void | sceKernelDcacheWritebackInvalidateAll (void)
| Write back and invalidate the data cache.
int | sceKernelUtilsMt19937Init (SceKernelUtilsMt19937Context *ctx, u32 seed)
| Function to initialise a mersenne twister context.
u32 | sceKernelUtilsMt19937UInt (SceKernelUtilsMt19937Context *ctx)
| Function to return a new psuedo random number.
int | sceKernelUtilsMd5Digest (u8 *data, u32 size, u8 *digest)
| Function to perform an MD5 digest of a data block.
int | sceKernelUtilsMd5BlockInit (SceKernelUtilsMd5Context *ctx)
| Function to initialise a MD5 digest context.
int | sceKernelUtilsMd5BlockUpdate (SceKernelUtilsMd5Context *ctx, u8 *data, u32 size)
| Function to update the MD5 digest with a block of data.
int | sceKernelUtilsMd5BlockResult (SceKernelUtilsMd5Context *ctx, u8 *digest)
| Function to get the digest result of the MD5 hash.
int | sceKernelUtilsSha1Digest (u8 *data, u32 size, u8 *digest)
| Function to SHA1 hash a data block.
int | sceKernelUtilsSha1BlockInit (SceKernelUtilsSha1Context *ctx)
| Function to initialise a context for SHA1 hashing.
int | sceKernelUtilsSha1BlockUpdate (SceKernelUtilsSha1Context *ctx, u8 *data, u32 size)
| Function to update the current hash.
int | sceKernelUtilsSha1BlockResult (SceKernelUtilsSha1Context *ctx, u8 *digest)
| Function to get the result of the SHA1 hash.

## Typedef Documentation

typedef struct _SceKernelUtilsMd5Context SceKernelUtilsMd5Context

| Structure to hold the MD5 context.

typedef struct _SceKernelUtilsMt19937Context SceKernelUtilsMt19937Context

| Structure for holding a mersenne twister context.

typedef struct _SceKernelUtilsSha1Context SceKernelUtilsSha1Context

| Type to hold a sha1 context.

## Function Documentation

void sceKernelDcacheWritebackAll | ( | void |  | ) |

| Write back the data cache to memory.

void sceKernelDcacheWritebackInvalidateAll | ( | void |  | ) |

| Write back and invalidate the data cache.

clock_t sceKernelLibcClock | ( | void |  | ) |

| Get the processor clock used since the start of the process.

int sceKernelLibcGettimeofday | ( | struct timeval * | tp,
|  | struct timezone * | tzp
| ) |

| Get the current time of time and time zone information.

time_t sceKernelLibcTime | ( | time_t * | t | ) |

| Get the time in seconds since the epoc (1st Jan 1970).

int sceKernelUtilsMd5BlockInit | ( | SceKernelUtilsMd5Context * | ctx | ) |

Function to initialise a MD5 digest context.

Parameters:

  | ctx | - A context block to initialise

Returns:
  < 0 on error.

Example:

       SceKernelUtilsMd5Context ctx;
       u8 digest[16];
       sceKernelUtilsMd5BlockInit(&ctx);
       sceKernelUtilsMd5BlockUpdate(&ctx, (u8*) "Hello", 5);
       sceKernelUtilsMd5BlockResult(&ctx, digest);

int sceKernelUtilsMd5BlockResult | ( | SceKernelUtilsMd5Context * | ctx,
|  | u8 * | digest
| ) |

Function to get the digest result of the MD5 hash.

Parameters:

  | ctx | - A filled in context block.
  | digest | - A 16 byte array to hold the digest.

Returns:
  < 0 on error.

int sceKernelUtilsMd5BlockUpdate | ( | SceKernelUtilsMd5Context * | ctx,
|  | u8 * | data,
|  | u32 | size
| ) |

Function to update the MD5 digest with a block of data.

Parameters:

  | ctx | - A filled in context block.
  | data | - The data block to hash.
  | size | - The size of the data to hash

Returns:
  < 0 on error.

int sceKernelUtilsMd5Digest | ( | u8 * | data,
|  | u32 | size,
|  | u8 * | digest
| ) |

Function to perform an MD5 digest of a data block.

Parameters:

  | data | - Pointer to a data block to make a digest of.
  | size | - Size of the data block.
  | digest | - Pointer to a 16byte buffer to store the resulting digest

Returns:
  < 0 on error.

int sceKernelUtilsMt19937Init | ( | SceKernelUtilsMt19937Context * | ctx,
|  | u32 | seed
| ) |

Function to initialise a mersenne twister context.

Parameters:

  | ctx | - Pointer to a context
  | seed | - A seed for the random function.

Example:

       SceKernelUtilsMt19937Context ctx;
       sceKernelUtilsMt19937Init(&ctx, time(NULL));
       u23 rand_val = sceKernelUtilsMt19937UInt(&ctx);

Returns:
  < 0 on error.

u32 sceKernelUtilsMt19937UInt | ( | SceKernelUtilsMt19937Context * | ctx | ) |

Function to return a new psuedo random number.

Parameters:

  | ctx | - Pointer to a pre-initialised context.

Returns:
  A pseudo random number (between 0 and MAX_INT).

int sceKernelUtilsSha1BlockInit | ( | SceKernelUtilsSha1Context * | ctx | ) |

Function to initialise a context for SHA1 hashing.

Parameters:

  | ctx | - Pointer to a context.

Returns:
  < 0 on error.

Example:

       SceKernelUtilsSha1Context ctx;
       u8 digest[20];
       sceKernelUtilsSha1BlockInit(&ctx);
       sceKernelUtilsSha1BlockUpdate(&ctx, (u8*) "Hello", 5);
       sceKernelUtilsSha1BlockResult(&ctx, digest);

int sceKernelUtilsSha1BlockResult | ( | SceKernelUtilsSha1Context * | ctx,
|  | u8 * | digest
| ) |

Function to get the result of the SHA1 hash.

Parameters:

  | ctx | - Pointer to a prefilled context.
  | digest | - A pointer to a 20 byte array to contain the digest.

Returns:
  < 0 on error.

int sceKernelUtilsSha1BlockUpdate | ( | SceKernelUtilsSha1Context * | ctx,
|  | u8 * | data,
|  | u32 | size
| ) |

Function to update the current hash.

Parameters:

  | ctx | - Pointer to a prefilled context.
  | data | - The data block to hash.
  | size | - The size of the data block

Returns:
  < 0 on error.

int sceKernelUtilsSha1Digest | ( | u8 * | data,
|  | u32 | size,
|  | u8 * | digest
| ) |

Function to SHA1 hash a data block.

Parameters:

  | data | - The data to hash.
  | size | - The size of the data.
  | digest | - Pointer to a 20 byte array for storing the digest

Returns:
  < 0 on error.