]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - lib/oid_registry.c
1 /* ASN.1 Object identifier (OID) registry
3 * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
12 #include <linux/export.h>
13 #include <linux/oid_registry.h>
14 #include "oid_registry_data.c"
17 * look_up_OID - Find an OID registration for the specified data
18 * @data: Binary representation of the OID
19 * @datasize: Size of the binary representation
21 enum OID
look_up_OID(const void *data
, size_t datasize
)
23 const unsigned char *octets
= data
;
26 unsigned i
, j
, k
, hash
;
29 /* Hash the OID data */
32 for (i
= 0; i
< datasize
; i
++)
33 hash
+= octets
[i
] * 33;
34 hash
= (hash
>> 24) ^ (hash
>> 16) ^ (hash
>> 8) ^ hash
;
37 /* Binary search the OID registry. OIDs are stored in ascending order
38 * of hash value then ascending order of size and then in ascending
39 * order of reverse value.
46 xhash
= oid_search_table
[j
].hash
;
56 oid
= oid_search_table
[j
].oid
;
57 len
= oid_index
[oid
+ 1] - oid_index
[oid
];
67 /* Variation is most likely to be at the tail end of the
68 * OID, so do the comparison in reverse.
71 unsigned char a
= oid_data
[oid_index
[oid
] + --len
];
72 unsigned char b
= octets
[len
];
89 EXPORT_SYMBOL_GPL(look_up_OID
);