fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 Amlogic Corporation. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #include <stdint.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <sys/types.h> |
| 19 | #include <limits.h> |
| 20 | |
| 21 | //namespace Tls { |
| 22 | unsigned int getU32( unsigned char *p ) |
| 23 | { |
| 24 | unsigned n; |
| 25 | |
| 26 | n= (p[0]<<24)|(p[1]<<16)|(p[2]<<8)|(p[3]); |
| 27 | |
| 28 | return n; |
| 29 | } |
| 30 | |
| 31 | int putU32( unsigned char *p, unsigned n ) |
| 32 | { |
| 33 | p[0]= (n>>24); |
| 34 | p[1]= (n>>16); |
| 35 | p[2]= (n>>8); |
| 36 | p[3]= (n&0xFF); |
| 37 | |
| 38 | return 4; |
| 39 | } |
| 40 | |
| 41 | int64_t getS64( unsigned char *p ) |
| 42 | { |
| 43 | int64_t n; |
| 44 | |
| 45 | n= ((((int64_t)(p[0]))<<56) | |
| 46 | (((int64_t)(p[1]))<<48) | |
| 47 | (((int64_t)(p[2]))<<40) | |
| 48 | (((int64_t)(p[3]))<<32) | |
| 49 | (((int64_t)(p[4]))<<24) | |
| 50 | (((int64_t)(p[5]))<<16) | |
| 51 | (((int64_t)(p[6]))<<8) | |
| 52 | (p[7]) ); |
| 53 | |
| 54 | return n; |
| 55 | } |
| 56 | |
| 57 | int putS64( unsigned char *p, int64_t n ) |
| 58 | { |
| 59 | p[0]= (((uint64_t)n)>>56); |
| 60 | p[1]= (((uint64_t)n)>>48); |
| 61 | p[2]= (((uint64_t)n)>>40); |
| 62 | p[3]= (((uint64_t)n)>>32); |
| 63 | p[4]= (((uint64_t)n)>>24); |
| 64 | p[5]= (((uint64_t)n)>>16); |
| 65 | p[6]= (((uint64_t)n)>>8); |
| 66 | p[7]= (((uint64_t)n)&0xFF); |
| 67 | |
| 68 | return 8; |
| 69 | } |
| 70 | //} |