iPXE
Data Structures | Macros | Functions | Variables
pccrc.h File Reference

Peer Content Caching and Retrieval: Content Identification [MS-PCCRC]. More...

#include <stdint.h>
#include <byteswap.h>
#include <ipxe/crypto.h>

Go to the source code of this file.

Data Structures

union  peerdist_info_version
 Content Information version number. More...
 
struct  peerdist_info_v1
 Content Information version 1 data structure header. More...
 
struct  peerdist_info_v1_segment
 Content Information version 1 segment description header. More...
 
struct  peerdist_info_v1_block
 Content Information version 1 block description header. More...
 
struct  peerdist_info_v2
 Content Information version 2 data structure header. More...
 
struct  peerdist_info_v2_chunk
 Content Information version 2 chunk description header. More...
 
struct  peerdist_info_v2_segment
 Content Information version 2 segment description header. More...
 
struct  peerdist_raw
 Raw content information. More...
 
struct  peerdist_range
 A content range. More...
 
struct  peerdist_info
 Content information. More...
 
struct  peerdist_info_segment
 A content information segment. More...
 
struct  peerdist_info_block
 A content information block. More...
 
struct  peerdist_info_operations
 Content information operations. More...
 

Macros

#define PEERDIST_INFO_V1   0x0100
 Content Information version 1. More...
 
#define PEERDIST_INFO_V2   0x0200
 Content Information version 2. More...
 
#define PEERDIST_INFO_V1_HASH_SHA256   0x0000800cUL
 SHA-256 hash algorithm. More...
 
#define PEERDIST_INFO_V1_HASH_SHA384   0x0000800dUL
 SHA-384 hash algorithm. More...
 
#define PEERDIST_INFO_V1_HASH_SHA512   0x0000800eUL
 SHA-512 hash algorithm. More...
 
#define peerdist_info_v1_segment_t(digestsize)
 Content Information version 1 segment description. More...
 
#define peerdist_info_v1_block_t(digestsize, blocks)
 Content Information version 1 block description. More...
 
#define PEERDIST_INFO_V2_HASH_SHA512_TRUNC   0x04
 SHA-512 hash algorithm with output truncated to first 256 bits. More...
 
#define peerdist_info_v2_chunk_t(digestsize)
 Content Information version 2 chunk description. More...
 
#define PEERDIST_INFO_V2_CHUNK_TYPE   0x00
 Chunk type. More...
 
#define peerdist_info_v2_segment_t(digestsize)
 Content Information version 2 segment description. More...
 
#define PEERDIST_DIGEST_MAX_SIZE   64
 Maximum digest size for any supported algorithm. More...
 
#define PEERDIST_SEGMENT_ID_MAGIC   L"MS_P2P_CACHING"
 Magic string constant used to calculate segment identifier. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
int peerdist_info (const void *data, size_t len, struct peerdist_info *info)
 Populate content information. More...
 
int peerdist_info_segment (const struct peerdist_info *info, struct peerdist_info_segment *segment, unsigned int index)
 Populate content information segment. More...
 
int peerdist_info_block (const struct peerdist_info_segment *segment, struct peerdist_info_block *block, unsigned int index)
 Populate content information block. More...
 

Variables

struct digest_algorithm sha512_trunc_algorithm
 

Detailed Description

Peer Content Caching and Retrieval: Content Identification [MS-PCCRC].

Definition in file pccrc.h.

Macro Definition Documentation

◆ PEERDIST_INFO_V1

#define PEERDIST_INFO_V1   0x0100

Content Information version 1.

Definition at line 46 of file pccrc.h.

◆ PEERDIST_INFO_V2

#define PEERDIST_INFO_V2   0x0200

Content Information version 2.

Definition at line 49 of file pccrc.h.

◆ PEERDIST_INFO_V1_HASH_SHA256

#define PEERDIST_INFO_V1_HASH_SHA256   0x0000800cUL

SHA-256 hash algorithm.

Definition at line 97 of file pccrc.h.

◆ PEERDIST_INFO_V1_HASH_SHA384

#define PEERDIST_INFO_V1_HASH_SHA384   0x0000800dUL

SHA-384 hash algorithm.

Definition at line 100 of file pccrc.h.

◆ PEERDIST_INFO_V1_HASH_SHA512

#define PEERDIST_INFO_V1_HASH_SHA512   0x0000800eUL

SHA-512 hash algorithm.

Definition at line 103 of file pccrc.h.

◆ peerdist_info_v1_segment_t

#define peerdist_info_v1_segment_t (   digestsize)
Value:
struct { \
uint8_t hash[digestsize]; \
uint8_t secret[digestsize]; \
} __attribute__ (( packed ))
#define __attribute__(x)
Definition: compiler.h:10
uint16_t segment
Code segment.
Definition: librm.h:138
pseudo_bit_t hash[0x00010]
Definition: arbel.h:13
Content Information version 1 segment description header.
Definition: pccrc.h:109
uint32_t digestsize
Digest size (i.e.
Definition: pccrr.h:15

Content Information version 1 segment description.

Parameters
digestsizeDigest size

Definition at line 146 of file pccrc.h.

◆ peerdist_info_v1_block_t

#define peerdist_info_v1_block_t (   digestsize,
  blocks 
)
Value:
struct { \
uint8_t hash[blocks][digestsize]; \
} __attribute__ (( packed ))
#define __attribute__(x)
Definition: compiler.h:10
pseudo_bit_t hash[0x00010]
Definition: arbel.h:13
Content Information version 1 block description header.
Definition: pccrc.h:157
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
uint32_t digestsize
Digest size (i.e.
Definition: pccrr.h:15

Content Information version 1 block description.

Parameters
digestsizeDigest size
blocksNumber of blocks

Definition at line 179 of file pccrc.h.

◆ PEERDIST_INFO_V2_HASH_SHA512_TRUNC

#define PEERDIST_INFO_V2_HASH_SHA512_TRUNC   0x04

SHA-512 hash algorithm with output truncated to first 256 bits.

Definition at line 225 of file pccrc.h.

◆ peerdist_info_v2_chunk_t

#define peerdist_info_v2_chunk_t (   digestsize)
Value:
struct { \
struct peerdist_info_v2_chunk chunk; \
peerdist_info_v2_segment_t ( digestsize ) segment[0]; \
} __attribute__ (( packed ))
#define __attribute__(x)
Definition: compiler.h:10
uint16_t segment
Code segment.
Definition: librm.h:138
uint32_t digestsize
Digest size (i.e.
Definition: pccrr.h:15
Content Information version 2 chunk description header.
Definition: pccrc.h:231

Content Information version 2 chunk description.

Parameters
digestsizeDigest size

Definition at line 250 of file pccrc.h.

◆ PEERDIST_INFO_V2_CHUNK_TYPE

#define PEERDIST_INFO_V2_CHUNK_TYPE   0x00

Chunk type.

Definition at line 257 of file pccrc.h.

◆ peerdist_info_v2_segment_t

#define peerdist_info_v2_segment_t (   digestsize)
Value:
struct { \
uint8_t hash[digestsize]; \
uint8_t secret[digestsize]; \
} __attribute__ (( packed ))
#define __attribute__(x)
Definition: compiler.h:10
uint16_t segment
Code segment.
Definition: librm.h:138
pseudo_bit_t hash[0x00010]
Definition: arbel.h:13
Content Information version 2 segment description header.
Definition: pccrc.h:263
uint32_t digestsize
Digest size (i.e.
Definition: pccrr.h:15

Content Information version 2 segment description.

Parameters
digestsizeDigest size

Definition at line 280 of file pccrc.h.

◆ PEERDIST_DIGEST_MAX_SIZE

#define PEERDIST_DIGEST_MAX_SIZE   64

Maximum digest size for any supported algorithm.

The largest digest size that we support is for SHA-512 at 64 bytes

Definition at line 298 of file pccrc.h.

◆ PEERDIST_SEGMENT_ID_MAGIC

#define PEERDIST_SEGMENT_ID_MAGIC   L"MS_P2P_CACHING"

Magic string constant used to calculate segment identifier.

Note that the MS-PCCRC specification states that this constant is

"the null-terminated ASCII string constant "MS_P2P_CACHING"; string literals are all ASCII strings with NULL terminators unless otherwise noted."

The specification lies. This constant is a UTF-16LE string, not an ASCII string. The terminating wNUL is included within the constant.

Definition at line 391 of file pccrc.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ peerdist_info()

int peerdist_info ( const void *  data,
size_t  len,
struct peerdist_info info 
)

Populate content information.

Parameters
dataRaw data
lenLength of raw data
infoContent information to fill in
Return values
rcReturn status code

Definition at line 670 of file pccrc.c.

671  {
673  int rc;
674 
675  /* Initialise structure */
676  memset ( info, 0, sizeof ( *info ) );
677  info->raw.data = data;
678  info->raw.len = len;
679 
680  /* Get version */
681  if ( ( rc = peerdist_info_get ( info, &version, 0,
682  sizeof ( version ) ) ) != 0 ) {
683  DBGC ( info, "PCCRC %p could not get version: %s\n",
684  info, strerror ( rc ) );
685  return rc;
686  }
687  DBGC2 ( info, "PCCRC %p version %d.%d\n",
688  info, version.major, version.minor );
689 
690  /* Determine version */
691  switch ( version.raw ) {
692  case cpu_to_le16 ( PEERDIST_INFO_V1 ) :
694  break;
695  case cpu_to_le16 ( PEERDIST_INFO_V2 ) :
697  break;
698  default:
699  DBGC ( info, "PCCRC %p unsupported version %d.%d\n",
700  info, version.major, version.minor );
701  return -ENOTSUP;
702  }
703  assert ( info->op != NULL );
704  assert ( info->op->info != NULL );
705 
706  /* Populate content information */
707  if ( ( rc = info->op->info ( info ) ) != 0 )
708  return rc;
709 
710  DBGC2 ( info, "PCCRC %p range [%08zx,%08zx) covers [%08zx,%08zx) with "
711  "%d segments\n", info, info->range.start, info->range.end,
712  info->trim.start, info->trim.end, info->segments );
713  return 0;
714 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
u32 info
Definition: ar9003_mac.h:24
#define DBGC(...)
Definition: compiler.h:505
#define ENOTSUP
Operation not supported.
Definition: errno.h:590
static struct peerdist_info_operations peerdist_info_v1_operations
Content information version 1 operations.
Definition: pccrc.c:391
u32 version
Driver version.
Definition: ath9k_hw.c:1985
#define PEERDIST_INFO_V2
Content Information version 2.
Definition: pccrc.h:49
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
static int peerdist_info_get(const struct peerdist_info *info, void *data, size_t offset, size_t len)
Get raw data.
Definition: pccrc.c:79
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
#define DBGC2(...)
Definition: compiler.h:522
static struct peerdist_info_operations peerdist_info_v2_operations
Content information version 2 operations.
Definition: pccrc.c:649
#define cpu_to_le16(value)
Definition: byteswap.h:107
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
#define PEERDIST_INFO_V1
Content Information version 1.
Definition: pccrc.h:46
Content Information version number.
Definition: pccrc.h:28
void * memset(void *dest, int character, size_t len) __nonnull

References assert(), cpu_to_le16, data, DBGC, DBGC2, ENOTSUP, info, len, memset(), NULL, peerdist_info_get(), PEERDIST_INFO_V1, peerdist_info_v1_operations, PEERDIST_INFO_V2, peerdist_info_v2_operations, rc, strerror(), and version.

◆ peerdist_info_segment()

int peerdist_info_segment ( const struct peerdist_info info,
struct peerdist_info_segment segment,
unsigned int  index 
)

Populate content information segment.

Parameters
infoContent information
segmentContent information segment to fill in
indexSegment index
Return values
rcReturn status code

Definition at line 724 of file pccrc.c.

726  {
727  int rc;
728 
729  /* Sanity checks */
730  assert ( info != NULL );
731  assert ( info->op != NULL );
732  assert ( info->op->segment != NULL );
733  if ( index >= info->segments ) {
734  DBGC ( info, "PCCRC %p segment %d of [0,%d) out of range\n",
735  info, index, info->segments );
736  return -ERANGE;
737  }
738 
739  /* Initialise structure */
740  memset ( segment, 0, sizeof ( *segment ) );
741  segment->info = info;
742  segment->index = index;
743 
744  /* Populate content information segment */
745  if ( ( rc = info->op->segment ( segment ) ) != 0 )
746  return rc;
747 
748  DBGC2 ( info, "PCCRC %p segment %d range [%08zx,%08zx) with %d "
749  "blocks\n", info, segment->index, segment->range.start,
750  segment->range.end, segment->blocks );
751  DBGC2 ( info, "PCCRC %p segment %d digest %s\n", info, segment->index,
752  peerdist_info_hash_ntoa ( info, segment->hash ) );
753  DBGC2 ( info, "PCCRC %p segment %d secret %s\n", info, segment->index,
754  peerdist_info_hash_ntoa ( info, segment->secret ) );
755  DBGC2 ( info, "PCCRC %p segment %d identf %s\n", info, segment->index,
757  return 0;
758 }
uint16_t segment
Code segment.
Definition: librm.h:138
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static const char * peerdist_info_hash_ntoa(const struct peerdist_info *info, const void *hash)
Transcribe hash value (for debugging)
Definition: pccrc.c:56
u32 info
Definition: ar9003_mac.h:24
#define DBGC(...)
Definition: compiler.h:505
long index
Definition: bigint.h:65
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define ERANGE
Result too large.
Definition: errno.h:640
#define DBGC2(...)
Definition: compiler.h:522
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
void * memset(void *dest, int character, size_t len) __nonnull

References assert(), DBGC, DBGC2, ERANGE, index, info, memset(), NULL, peerdist_info_hash_ntoa(), rc, and segment.

◆ peerdist_info_block()

int peerdist_info_block ( const struct peerdist_info_segment segment,
struct peerdist_info_block block,
unsigned int  index 
)

Populate content information block.

Parameters
segmentContent information segment
blockContent information block to fill in
indexBlock index
Return values
rcReturn status code

Definition at line 768 of file pccrc.c.

770  {
771  const struct peerdist_info *info = segment->info;
772  size_t start;
773  size_t end;
774  int rc;
775 
776  /* Sanity checks */
777  assert ( segment != NULL );
778  assert ( info != NULL );
779  assert ( info->op != NULL );
780  assert ( info->op->block != NULL );
781  if ( index >= segment->blocks ) {
782  DBGC ( info, "PCCRC %p segment %d block %d of [0,%d) out of "
783  "range\n", info, segment->index, index, segment->blocks);
784  return -ERANGE;
785  }
786 
787  /* Initialise structure */
788  memset ( block, 0, sizeof ( *block ) );
789  block->segment = segment;
790  block->index = index;
791 
792  /* Populate content information block */
793  if ( ( rc = info->op->block ( block ) ) != 0 )
794  return rc;
795 
796  /* Calculate trimmed range */
797  start = block->range.start;
798  if ( start < info->trim.start )
799  start = info->trim.start;
800  end = block->range.end;
801  if ( end > info->trim.end )
802  end = info->trim.end;
803  if ( end < start )
804  end = start;
805  block->trim.start = start;
806  block->trim.end = end;
807 
808  DBGC2 ( info, "PCCRC %p segment %d block %d hash %s\n",
809  info, segment->index, block->index,
810  peerdist_info_hash_ntoa ( info, block->hash ) );
811  DBGC2 ( info, "PCCRC %p segment %d block %d range [%08zx,%08zx) covers "
812  "[%08zx,%08zx)\n", info, segment->index, block->index,
813  block->range.start, block->range.end, block->trim.start,
814  block->trim.end );
815  return 0;
816 }
uint16_t segment
Code segment.
Definition: librm.h:138
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static const char * peerdist_info_hash_ntoa(const struct peerdist_info *info, const void *hash)
Transcribe hash value (for debugging)
Definition: pccrc.c:56
u32 info
Definition: ar9003_mac.h:24
size_t start
Start offset.
Definition: pccrc.h:311
#define DBGC(...)
Definition: compiler.h:505
long index
Definition: bigint.h:65
uint32_t start
Starting offset.
Definition: netvsc.h:12
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct peerdist_range trim
Trimmed content range.
Definition: pccrc.h:341
Content information.
Definition: pccrc.h:317
#define ERANGE
Result too large.
Definition: errno.h:640
#define DBGC2(...)
Definition: compiler.h:522
uint8_t block[3][8]
DES-encrypted blocks.
Definition: mschapv2.h:12
uint32_t end
Ending offset.
Definition: netvsc.h:18
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
void * memset(void *dest, int character, size_t len) __nonnull

References assert(), block, DBGC, DBGC2, end, ERANGE, index, info, memset(), NULL, peerdist_info_hash_ntoa(), rc, segment, start, peerdist_range::start, and peerdist_info::trim.

Variable Documentation

◆ sha512_trunc_algorithm

struct digest_algorithm sha512_trunc_algorithm