g_eli.h (876d357fa7bc8aeb8d050dd8fe227dd4fd8ed4df) | g_eli.h (ae8b1f90fecd606bbf17c74500fec4f91a3c8c04) |
---|---|
1/*- 2 * Copyright (c) 2005-2011 Pawel Jakub Dawidek <pawel@dawidek.net> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 275 unchanged lines hidden (view full) --- 284 le32enc(p, md->md_iterations); p += sizeof(md->md_iterations); 285 bcopy(md->md_salt, p, sizeof(md->md_salt)); p += sizeof(md->md_salt); 286 bcopy(md->md_mkeys, p, sizeof(md->md_mkeys)); p += sizeof(md->md_mkeys); 287 *datap = p; 288} 289static __inline void 290eli_metadata_encode(struct g_eli_metadata *md, u_char *data) 291{ | 1/*- 2 * Copyright (c) 2005-2011 Pawel Jakub Dawidek <pawel@dawidek.net> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 275 unchanged lines hidden (view full) --- 284 le32enc(p, md->md_iterations); p += sizeof(md->md_iterations); 285 bcopy(md->md_salt, p, sizeof(md->md_salt)); p += sizeof(md->md_salt); 286 bcopy(md->md_mkeys, p, sizeof(md->md_mkeys)); p += sizeof(md->md_mkeys); 287 *datap = p; 288} 289static __inline void 290eli_metadata_encode(struct g_eli_metadata *md, u_char *data) 291{ |
292 uint32_t hash[4]; |
|
292 MD5_CTX ctx; 293 u_char *p; 294 295 p = data; 296 bcopy(md->md_magic, p, sizeof(md->md_magic)); 297 p += sizeof(md->md_magic); 298 le32enc(p, md->md_version); 299 p += sizeof(md->md_version); --- 15 unchanged lines hidden (view full) --- 315 panic("%s: Unsupported version %u.", __func__, 316 (u_int)md->md_version); 317#else 318 assert(!"Unsupported metadata version."); 319#endif 320 } 321 MD5Init(&ctx); 322 MD5Update(&ctx, data, p - data); | 293 MD5_CTX ctx; 294 u_char *p; 295 296 p = data; 297 bcopy(md->md_magic, p, sizeof(md->md_magic)); 298 p += sizeof(md->md_magic); 299 le32enc(p, md->md_version); 300 p += sizeof(md->md_version); --- 15 unchanged lines hidden (view full) --- 316 panic("%s: Unsupported version %u.", __func__, 317 (u_int)md->md_version); 318#else 319 assert(!"Unsupported metadata version."); 320#endif 321 } 322 MD5Init(&ctx); 323 MD5Update(&ctx, data, p - data); |
323 MD5Final(md->md_hash, &ctx); | 324 MD5Final((void *)hash, &ctx); 325 bcopy(hash, md->md_hash, sizeof(md->md_hash)); |
324 bcopy(md->md_hash, p, sizeof(md->md_hash)); 325} 326static __inline int 327eli_metadata_decode_v0(const u_char *data, struct g_eli_metadata *md) 328{ | 326 bcopy(md->md_hash, p, sizeof(md->md_hash)); 327} 328static __inline int 329eli_metadata_decode_v0(const u_char *data, struct g_eli_metadata *md) 330{ |
331 uint32_t hash[4]; |
|
329 MD5_CTX ctx; 330 const u_char *p; 331 332 p = data + sizeof(md->md_magic) + sizeof(md->md_version); 333 md->md_flags = le32dec(p); p += sizeof(md->md_flags); 334 md->md_ealgo = le16dec(p); p += sizeof(md->md_ealgo); 335 md->md_keylen = le16dec(p); p += sizeof(md->md_keylen); 336 md->md_provsize = le64dec(p); p += sizeof(md->md_provsize); 337 md->md_sectorsize = le32dec(p); p += sizeof(md->md_sectorsize); 338 md->md_keys = *p; p += sizeof(md->md_keys); 339 md->md_iterations = le32dec(p); p += sizeof(md->md_iterations); 340 bcopy(p, md->md_salt, sizeof(md->md_salt)); p += sizeof(md->md_salt); 341 bcopy(p, md->md_mkeys, sizeof(md->md_mkeys)); p += sizeof(md->md_mkeys); 342 MD5Init(&ctx); 343 MD5Update(&ctx, data, p - data); | 332 MD5_CTX ctx; 333 const u_char *p; 334 335 p = data + sizeof(md->md_magic) + sizeof(md->md_version); 336 md->md_flags = le32dec(p); p += sizeof(md->md_flags); 337 md->md_ealgo = le16dec(p); p += sizeof(md->md_ealgo); 338 md->md_keylen = le16dec(p); p += sizeof(md->md_keylen); 339 md->md_provsize = le64dec(p); p += sizeof(md->md_provsize); 340 md->md_sectorsize = le32dec(p); p += sizeof(md->md_sectorsize); 341 md->md_keys = *p; p += sizeof(md->md_keys); 342 md->md_iterations = le32dec(p); p += sizeof(md->md_iterations); 343 bcopy(p, md->md_salt, sizeof(md->md_salt)); p += sizeof(md->md_salt); 344 bcopy(p, md->md_mkeys, sizeof(md->md_mkeys)); p += sizeof(md->md_mkeys); 345 MD5Init(&ctx); 346 MD5Update(&ctx, data, p - data); |
344 MD5Final(md->md_hash, &ctx); | 347 MD5Final((void *)hash, &ctx); 348 bcopy(hash, md->md_hash, sizeof(md->md_hash)); |
345 if (bcmp(md->md_hash, p, 16) != 0) 346 return (EINVAL); 347 return (0); 348} 349 350static __inline int 351eli_metadata_decode_v1v2v3v4v5v6v7(const u_char *data, struct g_eli_metadata *md) 352{ | 349 if (bcmp(md->md_hash, p, 16) != 0) 350 return (EINVAL); 351 return (0); 352} 353 354static __inline int 355eli_metadata_decode_v1v2v3v4v5v6v7(const u_char *data, struct g_eli_metadata *md) 356{ |
357 uint32_t hash[4]; |
|
353 MD5_CTX ctx; 354 const u_char *p; 355 356 p = data + sizeof(md->md_magic) + sizeof(md->md_version); 357 md->md_flags = le32dec(p); p += sizeof(md->md_flags); 358 md->md_ealgo = le16dec(p); p += sizeof(md->md_ealgo); 359 md->md_keylen = le16dec(p); p += sizeof(md->md_keylen); 360 md->md_aalgo = le16dec(p); p += sizeof(md->md_aalgo); 361 md->md_provsize = le64dec(p); p += sizeof(md->md_provsize); 362 md->md_sectorsize = le32dec(p); p += sizeof(md->md_sectorsize); 363 md->md_keys = *p; p += sizeof(md->md_keys); 364 md->md_iterations = le32dec(p); p += sizeof(md->md_iterations); 365 bcopy(p, md->md_salt, sizeof(md->md_salt)); p += sizeof(md->md_salt); 366 bcopy(p, md->md_mkeys, sizeof(md->md_mkeys)); p += sizeof(md->md_mkeys); 367 MD5Init(&ctx); 368 MD5Update(&ctx, data, p - data); | 358 MD5_CTX ctx; 359 const u_char *p; 360 361 p = data + sizeof(md->md_magic) + sizeof(md->md_version); 362 md->md_flags = le32dec(p); p += sizeof(md->md_flags); 363 md->md_ealgo = le16dec(p); p += sizeof(md->md_ealgo); 364 md->md_keylen = le16dec(p); p += sizeof(md->md_keylen); 365 md->md_aalgo = le16dec(p); p += sizeof(md->md_aalgo); 366 md->md_provsize = le64dec(p); p += sizeof(md->md_provsize); 367 md->md_sectorsize = le32dec(p); p += sizeof(md->md_sectorsize); 368 md->md_keys = *p; p += sizeof(md->md_keys); 369 md->md_iterations = le32dec(p); p += sizeof(md->md_iterations); 370 bcopy(p, md->md_salt, sizeof(md->md_salt)); p += sizeof(md->md_salt); 371 bcopy(p, md->md_mkeys, sizeof(md->md_mkeys)); p += sizeof(md->md_mkeys); 372 MD5Init(&ctx); 373 MD5Update(&ctx, data, p - data); |
369 MD5Final(md->md_hash, &ctx); | 374 MD5Final((void *)hash, &ctx); 375 bcopy(hash, md->md_hash, sizeof(md->md_hash)); |
370 if (bcmp(md->md_hash, p, 16) != 0) 371 return (EINVAL); 372 return (0); 373} 374static __inline int 375eli_metadata_decode(const u_char *data, struct g_eli_metadata *md) 376{ 377 int error; --- 332 unchanged lines hidden --- | 376 if (bcmp(md->md_hash, p, 16) != 0) 377 return (EINVAL); 378 return (0); 379} 380static __inline int 381eli_metadata_decode(const u_char *data, struct g_eli_metadata *md) 382{ 383 int error; --- 332 unchanged lines hidden --- |