blob: 69f9b604829a7bd52bf14ec2940213156792fe46 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/curvecp/protocol.h"
#include "base/basictypes.h"
namespace net {
void uint16_pack(uchar* dest, uint16 val) {
*dest++ = val;
val >>= 8;
*dest++ = val;
val >>= 8;
}
uint16 uint16_unpack(uchar* src) {
uint16 result;
result = src[1];
result <<= 8;
result |= src[0];
return result;
}
void uint32_pack(uchar* dest, uint32 val) {
*dest++ = val;
val >>= 8;
*dest++ = val;
val >>= 8;
*dest++ = val;
val >>= 8;
*dest++ = val;
val >>= 8;
}
uint32 uint32_unpack(uchar* src) {
uint32 result;
result = src[3];
result <<= 8;
result |= src[2];
result <<= 8;
result |= src[1];
result <<= 8;
result |= src[0];
return result;
}
void uint64_pack(uchar* dest, uint64 val) {
*dest++ = val;
val >>= 8;
*dest++ = val;
val >>= 8;
*dest++ = val;
val >>= 8;
*dest++ = val;
val >>= 8;
*dest++ = val;
val >>= 8;
*dest++ = val;
val >>= 8;
*dest++ = val;
val >>= 8;
*dest++ = val;
val >>= 8;
}
uint64 uint64_unpack(uchar* src) {
uint64 result;
result = src[7];
result <<= 8;
result |= src[6];
result <<= 8;
result |= src[5];
result <<= 8;
result |= src[4];
result <<= 8;
result |= src[3];
result <<= 8;
result |= src[2];
result <<= 8;
result |= src[1];
result <<= 8;
result |= src[0];
return result;
}
} // namespace net
|