Example #1
0
File: tth.c Project: Tilka/ncdc
void tiger_final(tiger_ctx_t *ctx, char result[24]) {
  unsigned index = (unsigned)ctx->length & 63;
  guint64 *msg64 = (guint64 *)ctx->message;

  /* pad message and run for last block */

  /* append the byte 0x01 to the message */
  ctx->message[index++] = 0x01;

  /* if no room left in the message to store 64-bit message length */
  if(index > 56) {
    /* then fill the rest with zeros and process it */
    while(index < 64)
      ctx->message[index++] = 0;
    tiger_process_block(ctx->hash, msg64);
    index = 0;
  }
  while(index < 56)
    ctx->message[index++] = 0;
  msg64[7] = GUINT64_FROM_LE(ctx->length << 3);
  tiger_process_block(ctx->hash, msg64);

  /* save result hash */
  guint64 *res = (guint64 *)result;
  res[0] = GINT64_TO_LE(ctx->hash[0]);
  res[1] = GINT64_TO_LE(ctx->hash[1]);
  res[2] = GINT64_TO_LE(ctx->hash[2]);
}
Example #2
0
/** @internal Append a 64-bit integer to a BSON object.
 *
 * @param b is the BSON object to append to.
 * @param type is the int64-like type to append.
 * @param name is the key name.
 * @param i is the 64-bit value to append.
 *
 * @returns TRUE on success, FALSE otherwise.
 */
static inline gboolean
_bson_append_int64_element (bson *b, bson_type type, const gchar *name,
                            gint64 i)
{
  if (!_bson_append_element_header (b, type, name))
    return FALSE;

  _bson_append_int64 (b, GINT64_TO_LE (i));
  return TRUE;
}
Example #3
0
mongo_packet *
test_mongo_wire_generate_reply (gboolean valid, gint32 nreturn,
                                gboolean with_docs)
{
  mongo_reply_packet_header rh;
  mongo_packet_header h;
  mongo_packet *p;
  guint8 *data;
  gint data_size = sizeof (mongo_reply_packet_header);
  bson *b1 = NULL, *b2 = NULL;

  p = mongo_wire_packet_new ();

  h.opcode = (valid) ? GINT32_TO_LE (1) : GINT32_TO_LE (42);
  h.id = GINT32_TO_LE (1984);
  h.resp_to = GINT32_TO_LE (42);
  if (with_docs)
    {
      b1 = test_bson_generate_full ();
      b2 = test_bson_generate_full ();
      data_size += bson_size (b1) + bson_size (b2);
    }
  h.length = GINT32_TO_LE (sizeof (mongo_packet_header) + data_size);

  mongo_wire_packet_set_header (p, &h);

  data = g_try_malloc (data_size);

  rh.flags = 0;
  rh.cursor_id = GINT64_TO_LE ((gint64)12345);
  rh.start = 0;
  rh.returned = GINT32_TO_LE (nreturn);

  memcpy (data, &rh, sizeof (mongo_reply_packet_header));
  if (with_docs)
    {
      memcpy (data + sizeof (mongo_reply_packet_header),
              bson_data (b1), bson_size (b1));
      memcpy (data + sizeof (mongo_reply_packet_header) + bson_size (b1),
              bson_data (b2), bson_size (b2));
    }

  mongo_wire_packet_set_data (p, data, data_size);
  g_free (data);
  bson_free (b1);
  bson_free (b2);

  return p;
}
Example #4
0
/**
 * qmi_utils_write_gint64_to_buffer:
 * @buffer: a buffer.
 * @buffer_size: size of @buffer.
 * @endian: endianness of firmware value; swapped from host byte order if necessary
 * @in: location of the variable to be written.
 *
 * Writes a signed 64-bit integer into the buffer. The number to be written
 * is expected to be given in host endianness, and this method takes care of
 * converting the value written to the byte order specified by @endian.
 *
 * The user needs to make sure that the buffer is at least 8 bytes long.
 *
 * Also note that both @buffer and @buffer_size get updated after the 8 bytes
 * write.
 */
void
qmi_utils_write_gint64_to_buffer (guint8  **buffer,
                                  guint16  *buffer_size,
                                  QmiEndian endian,
                                  gint64   *in)
{
    gint64 tmp;

    g_assert (in != NULL);
    g_assert (buffer != NULL);
    g_assert (buffer_size != NULL);
    g_assert (*buffer_size >= 8);

    if (endian == QMI_ENDIAN_BIG)
        tmp = GINT64_TO_BE (*in);
    else
        tmp = GINT64_TO_LE (*in);
    memcpy (&(*buffer)[0], &tmp, sizeof (tmp));

    *buffer = &((*buffer)[8]);
    *buffer_size = (*buffer_size) - 8;
}