u2f-host: Yubico Universal 2nd Factor C Library

## u2f-host u2f-host |

## Functions

u2fh_rc | u2fh_global_init ()
void | u2fh_global_done ()
const char * | u2fh_strerror ()
const char * | u2fh_strerror_name ()
u2fh_rc | u2fh_devs_init ()
u2fh_rc | u2fh_devs_discover ()
void | u2fh_devs_done ()
u2fh_rc | u2fh_register ()
u2fh_rc | u2fh_authenticate ()
u2fh_rc | u2fh_sendrecv ()
u2fh_rc | u2fh_get_device_description ()
int | u2fh_is_alive ()

## Description

## Functions

### u2fh_global_init ()

    u2fh_rc
    u2fh_global_init (u2fh_initflags flags);

Initialize the library. This function is not guaranteed to be thread safe and must be invoked on application startup.

#### Parameters

flags | initialization flags, ORed u2fh_initflags. |

#### Returns

On success `U2FH_OK` (integer 0) is returned, and on errors an u2fh_rc error code.

### u2fh_global_done ()

    void
    u2fh_global_done (void);

Release all resources from the library. Call this function when no further use of the library is needed.

### u2fh_strerror ()

    const char *
    u2fh_strerror (int err);

Convert return code to human readable string explanation of the reason for the particular error code.

This string can be used to output a diagnostic message to the user.

This function is one of few in the library that can be used without a successful call to `u2fh_global_init()`.

#### Parameters

err | error code |

#### Returns

Returns a pointer to a statically allocated string containing an explanation of the error code `err` .

### u2fh_strerror_name ()

    const char *
    u2fh_strerror_name (int err);

Convert return code to human readable string representing the error code symbol itself. For example, u2fh_strerror_name(`U2FH_OK`) returns the string "U2FH_OK".

This string can be used to output a diagnostic message to the user.

This function is one of few in the library that can be used without a successful call to `u2fh_global_init()`.

#### Parameters

err | error code |

#### Returns

Returns a pointer to a statically allocated string containing a string version of the error code `err` , or NULL if the error code is not known.

### u2fh_devs_init ()

    u2fh_rc
    u2fh_devs_init (u2fh_devs **devs);

Initialize device handle.

#### Parameters

devs | pointer to u2fh_devs type to initialize. |

#### Returns

On success `U2FH_OK` (integer 0) is returned, on memory allocation errors `U2FH_MEMORY_ERROR` is returned, or another u2fh_rc error code is returned.

### u2fh_devs_discover ()

    u2fh_rc
    u2fh_devs_discover (u2fh_devs *devs,
                        unsigned *max_index);

Discover and open new devices. This function can safely be called several times and will free resources associated with unplugged devices and open new.

#### Parameters

devs | device handle, from `u2fh_devs_init()`. |
max_index | will on return be set to the maximum index, may be NULL; if there is 1 device this will be 0, if there are 2 devices this will be 1, and so on. |

#### Returns

On success, `U2FH_OK` (integer 0) is returned, when no U2F device could be found `U2FH_NO_U2F_DEVICE` is returned, or another u2fh_rc error code.

### u2fh_devs_done ()

    void
    u2fh_devs_done (u2fh_devs *devs);

Release all resources associated with `devs` . This function must be called when you are finished with a device handle.

#### Parameters

devs | device handle, from `u2fh_devs_init()`. |

### u2fh_register ()

    u2fh_rc
    u2fh_register (u2fh_devs *devs,
                   const char *challenge,
                   const char *origin,
                   char **response,
                   u2fh_cmdflags flags);

Perform the U2F Register operation.

#### Parameters

devs | a device set handle, from `u2fh_devs_init()` and `u2fh_devs_discover()`. |
challenge | string with JSON data containing the challenge. |
origin | U2F origin URL. |
response | pointer to output string with JSON data. |
flags | set of ORed u2fh_cmdflags values. |

#### Returns

On success `U2FH_OK` (integer 0) is returned, and on errors an u2fh_rc error code.

### u2fh_authenticate ()

    u2fh_rc
    u2fh_authenticate (u2fh_devs *devs,
                       const char *challenge,
                       const char *origin,
                       char **response,
                       u2fh_cmdflags flags);

Perform the U2F Authenticate operation.

#### Parameters

devs | a device handle, from `u2fh_devs_init()` and `u2fh_devs_discover()`. |
challenge | string with JSON data containing the challenge. |
origin | U2F origin URL. |
response | pointer to output string with JSON data. |
flags | set of ORed u2fh_cmdflags values. |

#### Returns

On success `U2FH_OK` (integer 0) is returned, and on errors an u2fh_rc error code.

### u2fh_sendrecv ()

    u2fh_rc
    u2fh_sendrecv (u2fh_devs *devs,
                   unsigned  index,
                   uint8_t cmd,
                   const unsigned char *send,
                   uint16_t sendlen,
                   unsigned char *recv,
                   size_t *recvlen);

Send a command with data to the device at `index` .

#### Parameters

devs | device handle, from `u2fh_devs_init()`. |
index | index of device |
cmd | command to run |
send | buffer of data to send |
sendlen | length of data to send |
recv | buffer of data to receive |
recvlen | length of data to receive |

#### Returns

`U2FH_OK` on success, another u2fh_rc error code otherwise.

### u2fh_get_device_description ()

    u2fh_rc
    u2fh_get_device_description (u2fh_devs *devs,
                                 unsigned  index,
                                 char *out,
                                 size_t *len);

Get the device description of the device at `index` . Stores the string in `out` .

#### Parameters

devs | device_handle, from `u2fh_devs_init()`. |
index | index of device |
out | buffer for storing device description |
len | maximum amount of data to store in `out` . Will be updated. |

#### Returns

`U2FH_OK` on success.

### u2fh_is_alive ()

    int
    u2fh_is_alive (u2fh_devs *devs,
                   unsigned  index);

Get the liveliness of the device `index` .

#### Parameters

devs | device_handle, from `u2fh_devs_init()`. |
index | index of device |

#### Returns

1 if the device is considered alive, 0 otherwise.

## Types and Values