1343171Sdim/* 2343171Sdim * Copyright (c) 2003-2005 Kungliga Tekniska H��gskolan 3353358Sdim * (Royal Institute of Technology, Stockholm, Sweden). 4353358Sdim * All rights reserved. 5353358Sdim * 6343171Sdim * Redistribution and use in source and binary forms, with or without 7343171Sdim * modification, are permitted provided that the following conditions 8343171Sdim * are met: 9343171Sdim * 10343171Sdim * 1. Redistributions of source code must retain the above copyright 11343171Sdim * notice, this list of conditions and the following disclaimer. 12343171Sdim * 13343171Sdim * 2. Redistributions in binary form must reproduce the above copyright 14343171Sdim * notice, this list of conditions and the following disclaimer in the 15343171Sdim * documentation and/or other materials provided with the distribution. 16343171Sdim * 17343171Sdim * 3. Neither the name of the Institute nor the names of its contributors 18343171Sdim * may be used to endorse or promote products derived from this software 19343171Sdim * without specific prior written permission. 20343171Sdim * 21343171Sdim * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22343171Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23343171Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24343171Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 25343171Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26343171Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27343171Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28343171Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29343171Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30343171Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31343171Sdim * SUCH DAMAGE. 32343171Sdim */ 33343171Sdim 34343171Sdim#include "der_locl.h" 35343171Sdim 36343171Sdimint 37343171Sdimder_heim_oid_cmp(const heim_oid *p, const heim_oid *q) 38343171Sdim{ 39343171Sdim if (p->length != q->length) 40343171Sdim return p->length - q->length; 41343171Sdim return memcmp(p->components, 42343171Sdim q->components, 43343171Sdim p->length * sizeof(*p->components)); 44343171Sdim} 45343171Sdim 46343171Sdimint 47343171Sdimder_heim_octet_string_cmp(const heim_octet_string *p, 48343171Sdim const heim_octet_string *q) 49343171Sdim{ 50343171Sdim if (p->length != q->length) 51343171Sdim return p->length - q->length; 52343171Sdim return memcmp(p->data, q->data, p->length); 53343171Sdim} 54343171Sdim 55343171Sdimint 56343171Sdimder_printable_string_cmp(const heim_printable_string *p, 57343171Sdim const heim_printable_string *q) 58343171Sdim{ 59343171Sdim return der_heim_octet_string_cmp(p, q); 60343171Sdim} 61343171Sdim 62343171Sdimint 63343171Sdimder_ia5_string_cmp(const heim_ia5_string *p, 64343171Sdim const heim_ia5_string *q) 65343171Sdim{ 66343171Sdim return der_heim_octet_string_cmp(p, q); 67343171Sdim} 68343171Sdim 69343171Sdimint 70343171Sdimder_heim_bit_string_cmp(const heim_bit_string *p, 71343171Sdim const heim_bit_string *q) 72343171Sdim{ 73343171Sdim int i, r1, r2; 74343171Sdim if (p->length != q->length) 75343171Sdim return p->length - q->length; 76343171Sdim i = memcmp(p->data, q->data, p->length / 8); 77343171Sdim if (i) 78343171Sdim return i; 79343171Sdim if ((p->length % 8) == 0) 80343171Sdim return 0; 81343171Sdim i = (p->length / 8); 82343171Sdim r1 = ((unsigned char *)p->data)[i]; 83343171Sdim r2 = ((unsigned char *)q->data)[i]; 84343171Sdim i = 8 - (p->length % 8); 85343171Sdim r1 = r1 >> i; 86343171Sdim r2 = r2 >> i; 87343171Sdim return r1 - r2; 88343171Sdim} 89343171Sdim 90343171Sdimint 91343171Sdimder_heim_integer_cmp(const heim_integer *p, 92343171Sdim const heim_integer *q) 93343171Sdim{ 94343171Sdim if (p->negative != q->negative) 95343171Sdim return q->negative - p->negative; 96343171Sdim if (p->length != q->length) 97343171Sdim return p->length - q->length; 98343171Sdim return memcmp(p->data, q->data, p->length); 99343171Sdim} 100343171Sdim 101343171Sdimint 102343171Sdimder_heim_bmp_string_cmp(const heim_bmp_string *p, const heim_bmp_string *q) 103343171Sdim{ 104343171Sdim if (p->length != q->length) 105343171Sdim return p->length - q->length; 106343171Sdim return memcmp(p->data, q->data, q->length * sizeof(q->data[0])); 107343171Sdim} 108343171Sdim 109343171Sdimint 110343171Sdimder_heim_universal_string_cmp(const heim_universal_string *p, 111343171Sdim const heim_universal_string *q) 112343171Sdim{ 113343171Sdim if (p->length != q->length) 114343171Sdim return p->length - q->length; 115343171Sdim return memcmp(p->data, q->data, q->length * sizeof(q->data[0])); 116343171Sdim} 117343171Sdim