aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2009-01-01 22:56:52 +0200
committerJouni Malinen <j@w1.fi>2009-01-01 22:56:52 +0200
commit79da74a20c0f61ded4c0fd203f054cf3783f54da (patch)
tree7026e9d131c454f430e4cb10058b0bb8cb65299e /src/utils
parent84f5b41fc1e7a74c343b42075e1708a19d44a63e (diff)
downloadexternal_wpa_supplicant_8_ti-79da74a20c0f61ded4c0fd203f054cf3783f54da.zip
external_wpa_supplicant_8_ti-79da74a20c0f61ded4c0fd203f054cf3783f54da.tar.gz
external_wpa_supplicant_8_ti-79da74a20c0f61ded4c0fd203f054cf3783f54da.tar.bz2
WPS: Generate UUID based on MAC address, if not set
Generate a SHA1 hash -based UUID from the local MAC address if the UUID was not configured. This makes it easier to prepare for WPS since there is no need to generate an UUID.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/uuid.c30
-rw-r--r--src/utils/uuid.h1
2 files changed, 31 insertions, 0 deletions
diff --git a/src/utils/uuid.c b/src/utils/uuid.c
index d8cc267..620d3d6 100644
--- a/src/utils/uuid.c
+++ b/src/utils/uuid.c
@@ -15,6 +15,8 @@
#include "includes.h"
#include "common.h"
+#include "crypto.h"
+#include "sha1.h"
#include "uuid.h"
int uuid_str2bin(const char *str, u8 *bin)
@@ -75,3 +77,31 @@ int is_nil_uuid(const u8 *uuid)
return 0;
return 1;
}
+
+
+void uuid_gen_mac_addr(const u8 *mac_addr, u8 *uuid)
+{
+ const u8 *addr[2];
+ size_t len[2];
+ u8 hash[SHA1_MAC_LEN];
+ u8 nsid[16] = {
+ 0x52, 0x64, 0x80, 0xf8,
+ 0xc9, 0x9b,
+ 0x4b, 0xe5,
+ 0xa6, 0x55,
+ 0x58, 0xed, 0x5f, 0x5d, 0x60, 0x84
+ };
+
+ addr[0] = nsid;
+ len[0] = sizeof(nsid);
+ addr[1] = mac_addr;
+ len[1] = 6;
+ sha1_vector(2, addr, len, hash);
+ os_memcpy(uuid, hash, 16);
+
+ /* Version: 5 = named-based version using SHA-1 */
+ uuid[6] = (5 << 4) | (uuid[6] & 0x0f);
+
+ /* Variant specified in RFC 4122 */
+ uuid[8] = 0x80 | (uuid[8] & 0x3f);
+}
diff --git a/src/utils/uuid.h b/src/utils/uuid.h
index 0759165..9fc2ba0 100644
--- a/src/utils/uuid.h
+++ b/src/utils/uuid.h
@@ -20,5 +20,6 @@
int uuid_str2bin(const char *str, u8 *bin);
int uuid_bin2str(const u8 *bin, char *str, size_t max_len);
int is_nil_uuid(const u8 *uuid);
+void uuid_gen_mac_addr(const u8 *mac_addr, u8 *uuid);
#endif /* UUID_H */