taskrambler  0.1.9
Web server and task management solution.
version5.c
Go to the documentation of this file.
1 /**
2  * \file
3  *
4  * \author Georg Hopp
5  *
6  * \copyright
7  * Copyright © 2013 Georg Hopp
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 // for size_t
24 #include <sys/types.h>
25 
26 // for sha1 generation
27 #include <openssl/sha.h>
28 
29 // for htonl and similar
30 #include <arpa/inet.h>
31 
32 // for already available uuid functionality
33 #include "class.h"
34 #include "uuid.h"
35 
36 void _uuidFormat3or5(Uuid uuid, unsigned char hash[16], int version);
37 
38 Uuid
39 uuidVersion5(const unsigned char * name, size_t nname, Uuid nsid)
40 {
41  SHA_CTX ctx;
42  unsigned char hash[20];
43  Uuid net_nsid = clone(nsid);
44  Uuid uuid = new(Uuid);
45 
46  /*
47  * put the namespace id into network byte order.
48  */
49  (net_nsid->uuid).elements.time_low =
50  htonl((net_nsid->uuid).elements.time_low);
51  (net_nsid->uuid).elements.time_mid =
52  htons((net_nsid->uuid).elements.time_mid);
53  (net_nsid->uuid).elements.time_hi_version =
54  htons((net_nsid->uuid).elements.time_hi_version);
55 
56  /*
57  * generate the MD5
58  */
59  SHA1_Init(&ctx);
60  SHA1_Update(&ctx, (net_nsid->uuid).value, 16);
61  SHA1_Update(&ctx, name, nname);
62  SHA1_Final(hash, &ctx);
63 
64  delete(net_nsid);
65 
66  _uuidFormat3or5(uuid, hash, 5);
67 
68  return uuid;
69 }
70 
71 // vim: set ts=4 sw=4:
#define clone(object)
Uuid uuidVersion5(const unsigned char *name, size_t nname, Uuid nsid)
Definition: version5.c:39
void _uuidFormat3or5(Uuid uuid, unsigned char hash[16], int version)
Definition: _format3or5.c:36