コード例 #1
0
ファイル: n8_sks.c プロジェクト: eyberg/rumpkernel-netbsd-src
/*****************************************************************************
 * N8_SKSVerifyRSA
 *****************************************************************************/
N8_Status_t N8_SKSVerifyRSA(N8_SKSKeyHandle_t* keyHandle_p,
                            N8_Buffer_t* input_p, 
                            N8_Buffer_t* result_p)
{
   N8_RSAKeyObject_t privateKey;
   N8_Buffer_t* decryptBuffer_p;
   N8_Status_t ret;

   DBG(("Verify RSA Key.\n"));

   ret = N8_preamble();
   if (ret != N8_STATUS_OK)
   {
      return ret;
   }
   /* Set the material to NULL as we are using the SKS. */
   ret = N8_RSAInitializeKey(&privateKey, N8_PRIVATE_SKS, NULL, NULL);
   if (ret != N8_STATUS_OK)
   {
      DBG(("Could not initialize RSA private key from SKS. (%s)\n",
           N8_Status_t_text(ret)));
      return ret;
   }

   decryptBuffer_p = (N8_Buffer_t *) N8_UMALLOC(privateKey.privateKeyLength);
   if (decryptBuffer_p == NULL)
   {
      DBG(("Could not allocate %i bytes for decrypt buffer.\n", 
           privateKey.privateKeyLength));
      return N8_MALLOC_FAILED;
   }

   ret = N8_RSADecrypt(&privateKey, input_p,
                       privateKey.privateKeyLength,
                       decryptBuffer_p, NULL);
   if (ret != N8_STATUS_OK)
   {
      DBG(("Could not complete RSA decrypt using SKS private key. (%s)\n",
           N8_Status_t_text(ret)));
      return ret;
   }

   /* Compare the buffers. If they are different, then indicate this in the return code. */
   if (memcmp(result_p, decryptBuffer_p, privateKey.privateKeyLength) != 0)
   {
      DBG(("Message buffers are not the same. "
           "RSA Decrypt failed or SKS private key material is not valid.\n"));
      return N8_VERIFICATION_FAILED;
   }

   DBG(("RSA Decrypt good: SKS private key is valid.\n"));

   return N8_STATUS_OK;
} /* N8_SKSVerifyRSA */
コード例 #2
0
ファイル: n8_util.c プロジェクト: Tommmster/netbsd-avr32
/** @ingroup api_util
 * @brief Net Octave portable implementation of strdup
 *
 * Some compilers don't see strdup as an ansi function, so we wrote
 * our own.
 *
 * @param str_p RO: The string to duplicate.
 *
 * @par Externals:
 *    None.
 *
 * @return
 *    This function returns a pointer to the newly allocated copy of
 *    the string, or NULL if the input pointer is NULL or the
 *    N8_UMALLOC fails.
 *
 * @par Errors:
 *    See above.
 * 
 * @par Locks:
 *    None.
 *
 * @par Assumptions:
 *    The caller of this function takes the responsibility of
 *    freeing the string.
 *****************************************************************************/
char *n8_strdup(const char *str_p)
{
   char *ret_p;
   int   nBytes;

   if (str_p == NULL)
   {
      return(NULL);
   }

   nBytes = strlen(str_p);

   ret_p = N8_UMALLOC(nBytes + 1);

   if (ret_p == NULL)
   {
      return(NULL);
   }

   memcpy(ret_p, str_p, nBytes + 1);
   return(ret_p);
} /* n8_strdup */
コード例 #3
0
/** @ingroup user_util
 * @brief Allocate and return a N8_Buffer_t of hex values given an input string
 * representing hex digits.
 *
 *  @param e                   RO:  input string
 *
 * @par Externals
 *    None
 *
 * @return
 *    Pointer to created buffer.  NULL if the malloc failed.
 *
 * @par Errors
 *    None
 *
 * @par Assumptions
 *    Input string only contains hex characters ([0-9][a-f][A-F])
 *****************************************************************************/
N8_Buffer_t *N8_CreateBuffer(const char *e)
{
    int i,j;
    unsigned int temp;
    int len;
    int size;
    N8_Buffer_t *expected;
    len = strlen(e);
    size = (len+1) / 2;
    expected = (N8_Buffer_t *) N8_UMALLOC(size);

    if (expected == NULL)
        return NULL;

    j = 0;
    for (i = 0; i < len; i+=2)
    {
        sscanf(&e[i], "%2x", &temp);
        expected[j++] = (unsigned char) (temp & 0xff);
    }
    return expected;
} /* N8_CreateBuffer */
コード例 #4
0
/** @ingroup n8_event
 * @brief Allocates resources for the event queue and starts callback thread.
 *
 * This function is called by N8_InitializeAPI. It allocates resources used
 * by callback functions and starts a seperate thread if the timeout value is
 * non-zero. If the timeout is zero, the resources are allocated, but it is 
 * assume the user will be calling N8_EventPoll to complete the events.
 *
 * @par Externals
 *    n8_callback_gp    - Pointer to the callback threads data structure.
 *
 * @return
 *    N8_STATUS_OK - all's well.<br>
 *    N8_EVENT_ALLOC_FAILED - insufficient resources to allocate event array.<br>
 *
 * @par Errors
 *    <description of possible errors><br>
 *
 * @par Assumptions
 *****************************************************************************/
N8_Status_t callbackInit(uint32_t numEvents, uint32_t timeout)
{
   int dataSize = sizeof(N8_CallbackData_t) + 
	           ((numEvents + 1) * sizeof(N8_Event_t));

   n8_callbackData_gp = N8_UMALLOC(dataSize);
		                   
   if (n8_callbackData_gp == NULL)
   {
      return (N8_EVENT_ALLOC_FAILED);
   }

   memset(n8_callbackData_gp, 0, dataSize);
   N8_initProcessSem(&n8_callbackData_gp->eventLock);
   n8_callbackData_gp->eventMax = numEvents;
   if (timeout)
   {
      n8_callbackData_gp->n8_thread = TRUE;
      n8_callbackData_gp->timeout = timeout;
      N8_THREAD_INIT(n8_callbackThread, n8_callbackData_gp, n8_callbackThread_g);
   }

   return(N8_STATUS_OK);
}
コード例 #5
0
ファイル: n8_sks.c プロジェクト: eyberg/rumpkernel-netbsd-src
N8_Status_t N8_SKSVerifyDSA(N8_SKSKeyHandle_t* keyHandle_p, 
                            N8_Buffer_t* inputHash_p, 
                            N8_Buffer_t* resultRValue_p,
                            N8_Buffer_t* resultSValue_p)
{
   N8_DSAKeyObject_t privateKey;
   N8_Buffer_t* signRValueBuffer_p, *signSValueBuffer_p;
   N8_Status_t ret;
   DBG(("Verify DSA Key.\n"));

   ret = N8_preamble();
   if (ret != N8_STATUS_OK)
   {
      return ret;
   }

   /* Set the material to NULL as we are using the SKS. */
   ret = N8_DSAInitializeKey(&privateKey, N8_PRIVATE_SKS, NULL, NULL);
   if (ret != N8_STATUS_OK)
   {
      DBG(("Could not initialize DSA private key from SKS. (%s)\n",
           N8_Status_t_text(ret)));
      return ret;
   }

   /* !!!!!! Is there a #define for the S and R value byte lengths?!?!?!! */
   if ((signRValueBuffer_p = (N8_Buffer_t *) N8_UMALLOC(20)) != 0)
   {
      DBG(("Could not allocate %i bytes for DSA sign R value buffer.\n", 
           privateKey.modulusLength));
      return N8_MALLOC_FAILED;
   }

   if ((signSValueBuffer_p = (N8_Buffer_t *) N8_UMALLOC(20)) != 0)
   {
      DBG(("Could not allocate %i bytes for DSA sign S value buffer.\n", 
           privateKey.modulusLength));
      return N8_MALLOC_FAILED;
   }

   ret = N8_DSASign(&privateKey, inputHash_p, signRValueBuffer_p,
                    signSValueBuffer_p, NULL);
   if (ret != N8_STATUS_OK)
   {
      DBG(("Could not complete DSA sign using SKS private key. (%s)\n",
           N8_Status_t_text(ret)));
      return ret;
   }

   /* Compare the buffers. If they are different, then indicate this in the return code. */
   if (memcmp(resultRValue_p, signRValueBuffer_p, 20) != 0)
   {
      DBG(("Result R value buffers are not the same. "
           "DSA Sign failed or SKS private key material is not valid.\n"));
      return N8_VERIFICATION_FAILED;
   }

   if (memcmp(resultSValue_p, signSValueBuffer_p, 20) != 0)
   {
      DBG(("Result S value buffers are not the same.  "
           "DSA Sign failed or SKS private key material is not valid.\n"));
      return N8_VERIFICATION_FAILED;
   }

   DBG(("DSA Sign good: SKS private key is valid.\n"));

   return N8_STATUS_OK;

} /* N8_SKSVerifyDSA */