1 /** @file

2 Utility functions to generate checksum based on 2's complement

3 algorithm.

5 Copyright (c) 2007, Intel Corporation<BR>

6 All rights reserved. This program and the accompanying materials

7 are licensed and made available under the terms and conditions of the BSD License

8 which accompanies this distribution. The full text of the license may be found at

9 http://opensource.org/licenses/bsd-license.php

11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,

12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

14 Module Name: CheckSum.c

16 **/

18 /**

19 Calculate the sum of all elements in a buffer in unit of UINT8.

20 During calculation, the carry bits are dropped.

22 This function calculates the sum of all elements in a buffer

23 in unit of UINT8. The carry bits in result of addition are dropped.

24 The result is returned as UINT8. If Length is Zero, then Zero is

25 returned.

27 If Buffer is NULL, then ASSERT().

28 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().

30 @param Buffer Pointer to the buffer to carry out the sum operation.

31 @param Length The size, in bytes, of Buffer .

33 @return Sum The sum of Buffer with carry bits dropped during additions.

35 **/

36 UINT8

37 EFIAPI

40 IN UINTN Length

41 )

42 {

43 UINT8 Sum;

44 UINTN Count;

51 }

54 }

57 /**

58 Returns the two's complement checksum of all elements in a buffer

59 of 8-bit values.

61 This function first calculates the sum of the 8-bit values in the

62 buffer specified by Buffer and Length. The carry bits in the result

63 of addition are dropped. Then, the two's complement of the sum is

64 returned. If Length is 0, then 0 is returned.

66 If Buffer is NULL, then ASSERT().

67 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().

70 @param Buffer Pointer to the buffer to carry out the checksum operation.

71 @param Length The size, in bytes, of Buffer.

73 @return Checksum The 2's complement checksum of Buffer.

75 **/

76 UINT8

77 EFIAPI

80 IN UINTN Length

81 )

82 {

83 UINT8 CheckSum;

87 //

88 // Return the checksum based on 2's complement.

89 //

91 }

93 /**

94 Returns the sum of all elements in a buffer of 16-bit values. During

95 calculation, the carry bits are dropped.

97 This function calculates the sum of the 16-bit values in the buffer

98 specified by Buffer and Length. The carry bits in result of addition are dropped.

99 The 16-bit result is returned. If Length is 0, then 0 is returned.

101 If Buffer is NULL, then ASSERT().

102 If Buffer is not aligned on a 16-bit boundary, then ASSERT().

103 If Length is not aligned on a 16-bit boundary, then ASSERT().

104 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().

106 @param Buffer Pointer to the buffer to carry out the sum operation.

107 @param Length The size, in bytes, of Buffer.

109 @return Sum The sum of Buffer with carry bits dropped during additions.

111 **/

112 UINT16

113 EFIAPI

116 IN UINTN Length

117 )

118 {

119 UINT16 Sum;

120 UINTN Count;

130 }

133 }

136 /**

137 Returns the two's complement checksum of all elements in a buffer of

138 16-bit values.

140 This function first calculates the sum of the 16-bit values in the buffer

141 specified by Buffer and Length. The carry bits in the result of addition

142 are dropped. Then, the two's complement of the sum is returned. If Length

143 is 0, then 0 is returned.

145 If Buffer is NULL, then ASSERT().

146 If Buffer is not aligned on a 16-bit boundary, then ASSERT().

147 If Length is not aligned on a 16-bit boundary, then ASSERT().

148 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().

150 @param Buffer Pointer to the buffer to carry out the checksum operation.

151 @param Length The size, in bytes, of Buffer.

153 @return Checksum The 2's complement checksum of Buffer.

155 **/

156 UINT16

157 EFIAPI

160 IN UINTN Length

161 )

162 {

163 UINT16 CheckSum;

167 //

168 // Return the checksum based on 2's complement.

169 //

171 }

174 /**

175 Returns the sum of all elements in a buffer of 32-bit values. During

176 calculation, the carry bits are dropped.

178 This function calculates the sum of the 32-bit values in the buffer

179 specified by Buffer and Length. The carry bits in result of addition are dropped.

180 The 32-bit result is returned. If Length is 0, then 0 is returned.

182 If Buffer is NULL, then ASSERT().

183 If Buffer is not aligned on a 32-bit boundary, then ASSERT().

184 If Length is not aligned on a 32-bit boundary, then ASSERT().

185 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().

187 @param Buffer Pointer to the buffer to carry out the sum operation.

188 @param Length The size, in bytes, of Buffer.

190 @return Sum The sum of Buffer with carry bits dropped during additions.

192 **/

193 UINT32

194 EFIAPI

197 IN UINTN Length

198 )

199 {

200 UINT32 Sum;

201 UINTN Count;

211 }

214 }

217 /**

218 Returns the two's complement checksum of all elements in a buffer of

219 32-bit values.

221 This function first calculates the sum of the 32-bit values in the buffer

222 specified by Buffer and Length. The carry bits in the result of addition

223 are dropped. Then, the two's complement of the sum is returned. If Length

224 is 0, then 0 is returned.

226 If Buffer is NULL, then ASSERT().

227 If Buffer is not aligned on a 32-bit boundary, then ASSERT().

228 If Length is not aligned on a 32-bit boundary, then ASSERT().

229 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().

231 @param Buffer Pointer to the buffer to carry out the checksum operation.

232 @param Length The size, in bytes, of Buffer.

234 @return Checksum The 2's complement checksum of Buffer.

236 **/

237 UINT32

238 EFIAPI

241 IN UINTN Length

242 )

243 {

244 UINT32 CheckSum;

248 //

249 // Return the checksum based on 2's complement.

250 //

252 }

255 /**

256 Returns the sum of all elements in a buffer of 64-bit values. During

257 calculation, the carry bits are dropped.

259 This function calculates the sum of the 64-bit values in the buffer

260 specified by Buffer and Length. The carry bits in result of addition are dropped.

261 The 64-bit result is returned. If Length is 0, then 0 is returned.

263 If Buffer is NULL, then ASSERT().

264 If Buffer is not aligned on a 64-bit boundary, then ASSERT().

265 If Length is not aligned on a 64-bit boundary, then ASSERT().

266 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().

268 @param Buffer Pointer to the buffer to carry out the sum operation.

269 @param Length The size, in bytes, of Buffer.

271 @return Sum The sum of Buffer with carry bits dropped during additions.

273 **/

274 UINT64

275 EFIAPI

278 IN UINTN Length

279 )

280 {

281 UINT64 Sum;

282 UINTN Count;

291 }

294 }

297 /**

298 Returns the two's complement checksum of all elements in a buffer of

299 64-bit values.

301 This function first calculates the sum of the 64-bit values in the buffer

302 specified by Buffer and Length. The carry bits in the result of addition

303 are dropped. Then, the two's complement of the sum is returned. If Length

304 is 0, then 0 is returned.

306 If Buffer is NULL, then ASSERT().

307 If Buffer is not aligned on a 64-bit boundary, then ASSERT().

308 If Length is not aligned on a 64-bit boundary, then ASSERT().

309 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().

311 @param Buffer Pointer to the buffer to carry out the checksum operation.

312 @param Length The size, in bytes, of Buffer.

314 @return Checksum The 2's complement checksum of Buffer.

316 **/

317 UINT64

318 EFIAPI

321 IN UINTN Length

322 )

323 {

324 UINT64 CheckSum;

328 //

329 // Return the checksum based on 2's complement.

330 //

332 }