static int rainbow_verify( void *ctx, md_type_t md_alg,
                       const unsigned char *hash, size_t hash_len,
                       const unsigned char *sig, size_t sig_len )
{
    int ret;
    unsigned char QQ_buffer[RB_DIGEST_SIZE_BYTE] = { 0 };
    unsigned int n_bytes = ( hash_len < RB_DIGEST_SIZE_BYTE ) ? hash_len : RB_DIGEST_SIZE_BYTE;
    unsigned int _i = 0;

    ((void) md_alg);

    for (_i = 0; _i < n_bytes; ++_i) {
        QQ_buffer[_i] = hash[_i];
    }

    //if (hash_len < RB_DIGEST_SIZE_BYTE) {
    //    /* In fact we need another error code here */
    //    return POLARSSL_ERR_PK_SIG_LEN_MISMATCH;
    //}

    if (sig_len != RB_SIGNATURE_SIZE_BYTE) {
        return POLARSSL_ERR_PK_SIG_LEN_MISMATCH;
    }

    ret = rb_verify( QQ_buffer, (const uint8_t *)&((rainbow_context *) ctx)->pk, sig );
    if (ret != 0) {
        /* In fact we need a proper error code here */
        return -1;
    }
    return 0;
}
Beispiel #2
0
void rb_link(struct rb_tree *t, struct rb_node *n, struct rb_callbacks *cb) {
  /* reset node state other than the parent the node is to be linked to */
  n->left = NULL;
  n->right = NULL;
  n->color = RB_RED;

  /* set initial root */
  if (!t->root) {
    t->root = n;
  }

  /* adjust tree, starting at the newly inserted node, to satisfy the
     properties of a valid red-black tree */
  rb_link_1(t, n, cb);

  /* force root to black */
  t->root->color = RB_BLACK;

  /* fix up each node in the chain */
  if (cb && cb->propagate) {
    cb->propagate(t, n);
  }

#if VERIFY_TREE
  rb_verify(t->root);
#endif
}
Beispiel #3
0
void rb_unlink(struct rb_tree *t, struct rb_node *n, struct rb_callbacks *cb) {
  CHECK(!rb_empty_node(n));

  /* when deleting a node with two non-leaf children, we swap the node with
     its in-order predecessor (the maximum or rightmost element in the left
     subtree), and then delete the original node which now has only one
     non-leaf child */
  if (n->left && n->right) {
    struct rb_node *pred = rb_max(n->left);
    rb_swap_node(t, n, pred);
  }

  /* a node with at most one non-leaf child can simply be replaced with its
     non-leaf child */
  CHECK(!n->left || !n->right);
  struct rb_node *child = n->right ? n->right : n->left;
  if (rb_color(n) == RB_BLACK) {
    rb_unlink_1(t, n, cb);
  }
  rb_replace_node(t, n, child);

  /* force root to black */
  if (t->root) {
    t->root->color = RB_BLACK;
  }

  /* fix up each node in the parent chain */
  if (cb && cb->propagate) {
    cb->propagate(t, n->parent);
  }

  /* clear node state to support rb_empty_node */
  memset(n, 0, sizeof(*n));

#if VERIFY_TREE
  rb_verify(t->root);
#endif
}