diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2016-12-08 23:24:28 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-08 23:24:28 -0500 |
commit | 9258a1cae3985ee590f1c698451bd7909aa38d2b (patch) | |
tree | 8351f4b8fd8ff0895fe72a527e5718d00daa67a1 /src/libsystemd/sd-id128/sd-id128.c | |
parent | 1aa68db1ae44e1c69a007eaf011099a00b367bdd (diff) | |
parent | 70fc4f57902290c48bec9acb2393ded84c09d4ca (diff) |
Merge pull request #4686 from poettering/machine-id-app-specific
Add new "khash" API and add new sd_id128_get_machine_app_specific() function
Diffstat (limited to 'src/libsystemd/sd-id128/sd-id128.c')
-rw-r--r-- | src/libsystemd/sd-id128/sd-id128.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/libsystemd/sd-id128/sd-id128.c b/src/libsystemd/sd-id128/sd-id128.c index d4450c70a0..0d673ba655 100644 --- a/src/libsystemd/sd-id128/sd-id128.c +++ b/src/libsystemd/sd-id128/sd-id128.c @@ -27,6 +27,7 @@ #include "hexdecoct.h" #include "id128-util.h" #include "io-util.h" +#include "khash.h" #include "macro.h" #include "random-util.h" #include "util.h" @@ -181,3 +182,34 @@ _public_ int sd_id128_randomize(sd_id128_t *ret) { *ret = make_v4_uuid(t); return 0; } + +_public_ int sd_id128_get_machine_app_specific(sd_id128_t app_id, sd_id128_t *ret) { + _cleanup_(khash_unrefp) khash *h = NULL; + sd_id128_t m, result; + const void *p; + int r; + + assert_return(ret, -EINVAL); + + r = sd_id128_get_machine(&m); + if (r < 0) + return r; + + r = khash_new_with_key(&h, "hmac(sha256)", &m, sizeof(m)); + if (r < 0) + return r; + + r = khash_put(h, &app_id, sizeof(app_id)); + if (r < 0) + return r; + + r = khash_digest_data(h, &p); + if (r < 0) + return r; + + /* We chop off the trailing 16 bytes */ + memcpy(&result, p, MIN(khash_get_size(h), sizeof(result))); + + *ret = make_v4_uuid(result); + return 0; +} |