ReactOS  0.4.13-dev-482-ge57f103
base64_codec.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

SECURITY_STATUS encodeBase64 (PBYTE in_buf, int in_len, char *out_buf, int max_len, int *out_len) DECLSPEC_HIDDEN
 
SECURITY_STATUS decodeBase64 (char *in_buf, int in_len, BYTE *out_buf, int max_len, int *out_len) DECLSPEC_HIDDEN
 

Function Documentation

◆ decodeBase64()

SECURITY_STATUS decodeBase64 ( char in_buf,
int  in_len,
BYTE out_buf,
int  max_len,
int out_len 
)

◆ encodeBase64()

SECURITY_STATUS encodeBase64 ( PBYTE  in_buf,
int  in_len,
char out_buf,
int  max_len,
int out_len 
)

Definition at line 29 of file base64_codec.c.

31 {
32  int div, i;
33  PBYTE d = in_buf;
34  int bytes = (in_len*8 + 5)/6, pad_bytes = (bytes % 4) ? 4 - (bytes % 4) : 0;
35 
36  TRACE("bytes is %d, pad bytes is %d\n", bytes, pad_bytes);
37  *out_len = bytes + pad_bytes;
38 
39  if(bytes + pad_bytes + 1 > max_len)
41 
42  /* Three bytes of input give 4 chars of output */
43  div = in_len / 3;
44 
45  i = 0;
46  while(div > 0)
47  {
48  /* first char is the first 6 bits of the first byte*/
49  out_buf[i + 0] = b64[ ( d[0] >> 2) & 0x3f ];
50  /* second char is the last 2 bits of the first byte and the first 4
51  * bits of the second byte */
52  out_buf[i + 1] = b64[ ((d[0] << 4) & 0x30) | (d[1] >> 4 & 0x0f)];
53  /* third char is the last 4 bits of the second byte and the first 2
54  * bits of the third byte */
55  out_buf[i + 2] = b64[ ((d[1] << 2) & 0x3c) | (d[2] >> 6 & 0x03)];
56  /* fourth char is the remaining 6 bits of the third byte */
57  out_buf[i + 3] = b64[ d[2] & 0x3f];
58  i += 4;
59  d += 3;
60  div--;
61  }
62 
63  switch(pad_bytes)
64  {
65  case 1:
66  /* first char is the first 6 bits of the first byte*/
67  out_buf[i + 0] = b64[ ( d[0] >> 2) & 0x3f ];
68  /* second char is the last 2 bits of the first byte and the first 4
69  * bits of the second byte */
70  out_buf[i + 1] = b64[ ((d[0] << 4) & 0x30) | (d[1] >> 4 & 0x0f)];
71  /* third char is the last 4 bits of the second byte padded with
72  * two zeroes */
73  out_buf[i + 2] = b64[ ((d[1] << 2) & 0x3c) ];
74  /* fourth char is a = to indicate one byte of padding */
75  out_buf[i + 3] = '=';
76  out_buf[i + 4] = 0;
77  break;
78  case 2:
79  /* first char is the first 6 bits of the first byte*/
80  out_buf[i + 0] = b64[ ( d[0] >> 2) & 0x3f ];
81  /* second char is the last 2 bits of the first byte padded with
82  * four zeroes*/
83  out_buf[i + 1] = b64[ ((d[0] << 4) & 0x30)];
84  /* third char is = to indicate padding */
85  out_buf[i + 2] = '=';
86  /* fourth char is = to indicate padding */
87  out_buf[i + 3] = '=';
88  out_buf[i + 4] = 0;
89  break;
90  default:
91  out_buf[i] = 0;
92  }
93 
94  return SEC_E_OK;
95 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
static const char b64[]
Definition: base64_codec.c:26
#define TRACE(s)
Definition: solgame.cpp:4
#define d
Definition: ke_i.h:81
_STLP_VENDOR_CSTD::ldiv_t div(long __x, long __y)
Definition: _cstdlib.h:137
#define SEC_E_OK
Definition: winerror.h:2356
#define SEC_E_BUFFER_TOO_SMALL
Definition: winerror.h:2937
BYTE * PBYTE
Definition: pedump.c:66

Referenced by ntlm_AcceptSecurityContext(), and ntlm_InitializeSecurityContextW().